2007-08-25 04:14:26 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
encoding.h -
|
|
|
|
|
|
|
|
$Author: matz $
|
|
|
|
created at: Thu May 24 11:49:41 JST 2007
|
|
|
|
|
|
|
|
Copyright (C) 2007 Yukihiro Matsumoto
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef RUBY_ENCODING_H
|
|
|
|
#define RUBY_ENCODING_H 1
|
|
|
|
|
2010-05-25 04:26:50 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#if 0
|
|
|
|
} /* satisfy cc-mode */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-06-10 02:24:45 +00:00
|
|
|
#include <stdarg.h>
|
2016-10-23 02:41:43 +00:00
|
|
|
#include "ruby/ruby.h"
|
2007-08-25 04:14:26 +00:00
|
|
|
#include "ruby/oniguruma.h"
|
|
|
|
|
2013-04-05 10:29:38 +00:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2010-07-21 21:38:25 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
enum ruby_encoding_consts {
|
|
|
|
RUBY_ENCODING_INLINE_MAX = 127,
|
|
|
|
RUBY_ENCODING_SHIFT = (RUBY_FL_USHIFT+10),
|
|
|
|
RUBY_ENCODING_MASK = (RUBY_ENCODING_INLINE_MAX<<RUBY_ENCODING_SHIFT
|
|
|
|
/* RUBY_FL_USER10..RUBY_FL_USER16 */),
|
|
|
|
RUBY_ENCODING_MAXNAMELEN = 42
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ENCODING_INLINE_MAX RUBY_ENCODING_INLINE_MAX
|
|
|
|
#define ENCODING_SHIFT RUBY_ENCODING_SHIFT
|
|
|
|
#define ENCODING_MASK RUBY_ENCODING_MASK
|
|
|
|
|
|
|
|
#define RB_ENCODING_SET_INLINED(obj,i) do {\
|
|
|
|
RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\
|
|
|
|
RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\
|
2008-01-07 02:49:01 +00:00
|
|
|
} while (0)
|
2015-09-13 02:03:31 +00:00
|
|
|
#define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i))
|
2008-01-07 02:49:01 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
#define RB_ENCODING_GET_INLINED(obj) \
|
|
|
|
(int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT)
|
|
|
|
#define RB_ENCODING_GET(obj) \
|
|
|
|
(RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \
|
|
|
|
RB_ENCODING_GET_INLINED(obj) : \
|
2008-05-19 08:25:03 +00:00
|
|
|
rb_enc_get_index(obj))
|
2008-01-07 02:49:01 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
#define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0)
|
|
|
|
|
|
|
|
#define ENCODING_SET_INLINED(obj,i) RB_ENCODING_SET_INLINED(obj,i)
|
|
|
|
#define ENCODING_SET(obj,i) RB_ENCODING_SET(obj,i)
|
|
|
|
#define ENCODING_GET_INLINED(obj) RB_ENCODING_GET_INLINED(obj)
|
|
|
|
#define ENCODING_GET(obj) RB_ENCODING_GET(obj)
|
|
|
|
#define ENCODING_IS_ASCII8BIT(obj) RB_ENCODING_IS_ASCII8BIT(obj)
|
|
|
|
#define ENCODING_MAXNAMELEN RUBY_ENCODING_MAXNAMELEN
|
|
|
|
|
|
|
|
enum ruby_coderange_type {
|
|
|
|
RUBY_ENC_CODERANGE_UNKNOWN = 0,
|
|
|
|
RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8),
|
|
|
|
RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9),
|
|
|
|
RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)),
|
|
|
|
RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT|
|
|
|
|
RUBY_ENC_CODERANGE_VALID|
|
|
|
|
RUBY_ENC_CODERANGE_BROKEN)
|
|
|
|
};
|
2008-01-16 05:55:22 +00:00
|
|
|
|
2015-07-17 06:39:29 +00:00
|
|
|
static inline int
|
|
|
|
rb_enc_coderange_clean_p(int cr)
|
|
|
|
{
|
2015-09-13 02:03:31 +00:00
|
|
|
return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
|
2015-07-17 06:39:29 +00:00
|
|
|
}
|
2015-09-13 02:03:31 +00:00
|
|
|
#define RB_ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr)
|
|
|
|
#define RB_ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK)
|
|
|
|
#define RB_ENC_CODERANGE_ASCIIONLY(obj) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT)
|
|
|
|
#define RB_ENC_CODERANGE_SET(obj,cr) (\
|
|
|
|
RBASIC(obj)->flags = \
|
|
|
|
(RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr))
|
|
|
|
#define RB_ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_SET((obj),0)
|
2008-02-17 13:01:52 +00:00
|
|
|
|
2008-09-09 11:59:40 +00:00
|
|
|
/* assumed ASCII compatibility */
|
2015-09-13 02:03:31 +00:00
|
|
|
#define RB_ENC_CODERANGE_AND(a, b) \
|
|
|
|
((a) == RUBY_ENC_CODERANGE_7BIT ? (b) : \
|
|
|
|
(a) != RUBY_ENC_CODERANGE_VALID ? RUBY_ENC_CODERANGE_UNKNOWN : \
|
|
|
|
(b) == RUBY_ENC_CODERANGE_7BIT ? RUBY_ENC_CODERANGE_VALID : (b))
|
2007-09-26 19:46:58 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
#define RB_ENCODING_CODERANGE_SET(obj, encindex, cr) \
|
2008-01-07 02:49:01 +00:00
|
|
|
do { \
|
|
|
|
VALUE rb_encoding_coderange_obj = (obj); \
|
2015-09-13 02:03:31 +00:00
|
|
|
RB_ENCODING_SET(rb_encoding_coderange_obj, (encindex)); \
|
|
|
|
RB_ENC_CODERANGE_SET(rb_encoding_coderange_obj, (cr)); \
|
2008-01-07 02:49:01 +00:00
|
|
|
} while (0)
|
2007-09-26 19:46:58 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
#define ENC_CODERANGE_MASK RUBY_ENC_CODERANGE_MASK
|
|
|
|
#define ENC_CODERANGE_UNKNOWN RUBY_ENC_CODERANGE_UNKNOWN
|
|
|
|
#define ENC_CODERANGE_7BIT RUBY_ENC_CODERANGE_7BIT
|
|
|
|
#define ENC_CODERANGE_VALID RUBY_ENC_CODERANGE_VALID
|
|
|
|
#define ENC_CODERANGE_BROKEN RUBY_ENC_CODERANGE_BROKEN
|
|
|
|
#define ENC_CODERANGE_CLEAN_P(cr) RB_ENC_CODERANGE_CLEAN_P(cr)
|
|
|
|
#define ENC_CODERANGE(obj) RB_ENC_CODERANGE(obj)
|
|
|
|
#define ENC_CODERANGE_ASCIIONLY(obj) RB_ENC_CODERANGE_ASCIIONLY(obj)
|
|
|
|
#define ENC_CODERANGE_SET(obj,cr) RB_ENC_CODERANGE_SET(obj,cr)
|
|
|
|
#define ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_CLEAR(obj)
|
|
|
|
#define ENC_CODERANGE_AND(a, b) RB_ENC_CODERANGE_AND(a, b)
|
|
|
|
#define ENCODING_CODERANGE_SET(obj, encindex, cr) RB_ENCODING_CODERANGE_SET(obj, encindex, cr)
|
|
|
|
|
2014-06-02 20:23:47 +00:00
|
|
|
typedef const OnigEncodingType rb_encoding;
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2010-08-11 20:58:11 +00:00
|
|
|
int rb_char_to_option_kcode(int c, int *option, int *kcode);
|
|
|
|
|
2007-12-10 12:47:55 +00:00
|
|
|
int rb_enc_replicate(const char *, rb_encoding *);
|
2007-12-21 11:00:04 +00:00
|
|
|
int rb_define_dummy_encoding(const char *);
|
2016-05-08 17:44:51 +00:00
|
|
|
PUREFUNC(int rb_enc_dummy_p(rb_encoding *enc));
|
|
|
|
PUREFUNC(int rb_enc_to_index(rb_encoding *enc));
|
2007-09-26 09:39:08 +00:00
|
|
|
int rb_enc_get_index(VALUE obj);
|
2008-05-19 08:25:03 +00:00
|
|
|
void rb_enc_set_index(VALUE obj, int encindex);
|
2018-06-28 08:35:48 +00:00
|
|
|
int rb_enc_capable(VALUE obj);
|
2007-09-28 19:27:10 +00:00
|
|
|
int rb_enc_find_index(const char *name);
|
2018-06-28 23:46:59 +00:00
|
|
|
int rb_enc_alias(const char *alias, const char *orig);
|
2007-10-13 16:32:40 +00:00
|
|
|
int rb_to_encoding_index(VALUE);
|
2014-06-02 20:23:47 +00:00
|
|
|
rb_encoding *rb_to_encoding(VALUE);
|
|
|
|
rb_encoding *rb_find_encoding(VALUE);
|
|
|
|
rb_encoding *rb_enc_get(VALUE);
|
|
|
|
rb_encoding *rb_enc_compatible(VALUE,VALUE);
|
|
|
|
rb_encoding *rb_enc_check(VALUE,VALUE);
|
2008-05-20 22:26:14 +00:00
|
|
|
VALUE rb_enc_associate_index(VALUE, int);
|
2014-06-02 20:23:47 +00:00
|
|
|
VALUE rb_enc_associate(VALUE, rb_encoding*);
|
2007-12-28 14:55:43 +00:00
|
|
|
void rb_enc_copy(VALUE dst, VALUE src);
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2014-06-02 20:23:47 +00:00
|
|
|
VALUE rb_enc_str_new(const char*, long, rb_encoding*);
|
|
|
|
VALUE rb_enc_str_new_cstr(const char*, rb_encoding*);
|
2014-09-19 05:53:00 +00:00
|
|
|
VALUE rb_enc_str_new_static(const char*, long, rb_encoding*);
|
2014-06-02 20:23:47 +00:00
|
|
|
VALUE rb_enc_reg_new(const char*, long, rb_encoding*, int);
|
|
|
|
PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3);
|
|
|
|
VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list);
|
|
|
|
long rb_enc_strlen(const char*, const char*, rb_encoding*);
|
|
|
|
char* rb_enc_nth(const char*, const char*, long, rb_encoding*);
|
2007-10-04 06:57:19 +00:00
|
|
|
VALUE rb_obj_encoding(VALUE);
|
2014-06-02 20:23:47 +00:00
|
|
|
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
|
|
|
|
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2014-06-02 20:23:47 +00:00
|
|
|
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
|
|
|
|
VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
|
|
|
|
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
|
|
|
|
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
|
2008-10-18 10:36:20 +00:00
|
|
|
|
2016-05-12 18:12:46 +00:00
|
|
|
#ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
|
Use RB_GNUC_EXTENSION_BLOCK instead of __extension__
* include/ruby/defines.h (RB_GNUC_EXTENSION, RB_GNUC_EXTENSION_BLOCK):
macros for skipping __extension__ on non-GCC compilers.
* eval_error.c (warn_print): use RB_GNUC_EXTENSION_BLOCK instead of
__extension__ because __extension__ is a GNU extension.
Fix compile error on Solaris 10 with Oracle Solaris Studio 12.x.
[Bug #12397] [ruby-dev:49629].
* internal.h (rb_fstring_cstr, rb_fstring_enc_cstr): ditto
* include/ruby/encoding.h (rb_enc_str_new, rb_enc_str_new_cstr): ditto
* include/ruby/intern.h (rb_str_new, rb_str_new_cstr,
rb_usascii_str_new, rb_utf8_str_new, rb_tainted_str_new_cstr,
rb_usascii_str_new_cstr, rb_utf8_str_new_cstr,
rb_external_str_new_cstr, rb_locale_str_new_cstr,
rb_str_buf_new_cstr, rb_str_cat_cstr, rb_exc_new_cstr): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 12:29:06 +00:00
|
|
|
#define rb_enc_str_new(str, len, enc) RB_GNUC_EXTENSION_BLOCK( \
|
2014-09-19 05:53:00 +00:00
|
|
|
(__builtin_constant_p(str) && __builtin_constant_p(len)) ? \
|
|
|
|
rb_enc_str_new_static((str), (len), (enc)) : \
|
Use RB_GNUC_EXTENSION_BLOCK instead of __extension__
* include/ruby/defines.h (RB_GNUC_EXTENSION, RB_GNUC_EXTENSION_BLOCK):
macros for skipping __extension__ on non-GCC compilers.
* eval_error.c (warn_print): use RB_GNUC_EXTENSION_BLOCK instead of
__extension__ because __extension__ is a GNU extension.
Fix compile error on Solaris 10 with Oracle Solaris Studio 12.x.
[Bug #12397] [ruby-dev:49629].
* internal.h (rb_fstring_cstr, rb_fstring_enc_cstr): ditto
* include/ruby/encoding.h (rb_enc_str_new, rb_enc_str_new_cstr): ditto
* include/ruby/intern.h (rb_str_new, rb_str_new_cstr,
rb_usascii_str_new, rb_utf8_str_new, rb_tainted_str_new_cstr,
rb_usascii_str_new_cstr, rb_utf8_str_new_cstr,
rb_external_str_new_cstr, rb_locale_str_new_cstr,
rb_str_buf_new_cstr, rb_str_cat_cstr, rb_exc_new_cstr): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 12:29:06 +00:00
|
|
|
rb_enc_str_new((str), (len), (enc)) \
|
|
|
|
)
|
|
|
|
#define rb_enc_str_new_cstr(str, enc) RB_GNUC_EXTENSION_BLOCK( \
|
2013-09-03 13:03:54 +00:00
|
|
|
(__builtin_constant_p(str)) ? \
|
2014-09-19 05:53:00 +00:00
|
|
|
rb_enc_str_new_static((str), (long)strlen(str), (enc)) : \
|
Use RB_GNUC_EXTENSION_BLOCK instead of __extension__
* include/ruby/defines.h (RB_GNUC_EXTENSION, RB_GNUC_EXTENSION_BLOCK):
macros for skipping __extension__ on non-GCC compilers.
* eval_error.c (warn_print): use RB_GNUC_EXTENSION_BLOCK instead of
__extension__ because __extension__ is a GNU extension.
Fix compile error on Solaris 10 with Oracle Solaris Studio 12.x.
[Bug #12397] [ruby-dev:49629].
* internal.h (rb_fstring_cstr, rb_fstring_enc_cstr): ditto
* include/ruby/encoding.h (rb_enc_str_new, rb_enc_str_new_cstr): ditto
* include/ruby/intern.h (rb_str_new, rb_str_new_cstr,
rb_usascii_str_new, rb_utf8_str_new, rb_tainted_str_new_cstr,
rb_usascii_str_new_cstr, rb_utf8_str_new_cstr,
rb_external_str_new_cstr, rb_locale_str_new_cstr,
rb_str_buf_new_cstr, rb_str_cat_cstr, rb_exc_new_cstr): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 12:29:06 +00:00
|
|
|
rb_enc_str_new_cstr((str), (enc)) \
|
|
|
|
)
|
2013-09-03 13:03:54 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-02 20:23:47 +00:00
|
|
|
PRINTF_ARGS(NORETURN(void rb_enc_raise(rb_encoding *, VALUE, const char*, ...)), 3, 4);
|
2012-04-10 10:07:07 +00:00
|
|
|
|
2007-08-25 04:14:26 +00:00
|
|
|
/* index -> rb_encoding */
|
2014-06-02 20:23:47 +00:00
|
|
|
rb_encoding *rb_enc_from_index(int idx);
|
2007-08-25 04:14:26 +00:00
|
|
|
|
|
|
|
/* name -> rb_encoding */
|
2014-06-02 20:23:47 +00:00
|
|
|
rb_encoding *rb_enc_find(const char *name);
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2008-09-12 11:31:28 +00:00
|
|
|
/* rb_encoding * -> name */
|
2007-08-25 04:14:26 +00:00
|
|
|
#define rb_enc_name(enc) (enc)->name
|
|
|
|
|
2008-09-12 11:31:28 +00:00
|
|
|
/* rb_encoding * -> minlen/maxlen */
|
2007-08-25 04:14:26 +00:00
|
|
|
#define rb_enc_mbminlen(enc) (enc)->min_enc_len
|
|
|
|
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
|
|
|
|
|
2007-12-23 15:19:23 +00:00
|
|
|
/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
|
2007-08-27 13:48:09 +00:00
|
|
|
|
2009-05-20 04:44:36 +00:00
|
|
|
/* -> mbclen (only for valid encoding) */
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc);
|
2009-05-20 04:44:36 +00:00
|
|
|
|
2007-12-11 03:08:50 +00:00
|
|
|
/* -> chlen, invalid or needmore */
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc);
|
2008-01-27 14:27:07 +00:00
|
|
|
#define MBCLEN_CHARFOUND_P(ret) ONIGENC_MBCLEN_CHARFOUND_P(ret)
|
|
|
|
#define MBCLEN_CHARFOUND_LEN(ret) ONIGENC_MBCLEN_CHARFOUND_LEN(ret)
|
|
|
|
#define MBCLEN_INVALID_P(ret) ONIGENC_MBCLEN_INVALID_P(ret)
|
|
|
|
#define MBCLEN_NEEDMORE_P(ret) ONIGENC_MBCLEN_NEEDMORE_P(ret)
|
|
|
|
#define MBCLEN_NEEDMORE_LEN(ret) ONIGENC_MBCLEN_NEEDMORE_LEN(ret)
|
2007-12-06 09:28:26 +00:00
|
|
|
|
2007-12-11 03:08:50 +00:00
|
|
|
/* -> 0x00..0x7f, -1 */
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc);
|
2007-12-08 02:50:43 +00:00
|
|
|
|
* encoding.c (rb_enc_codepoint_len): combine rb_enc_codepoint()
and rb_enc_codelen() in one function to reduce calls.
* encoding.c (rb_enc_codepoint): compatibility function.
* sprintf.c (rb_str_format): use rb_enc_codepoint_len().
* string.c (rb_str_inspect, rb_str_upcase_bang,
rb_str_downcase_bang, rb_str_capitalize_bang,
rb_str_swapcase_bang, trnext, tr_trans, rb_str_delete_bang,
rb_str_squeeze_bang, rb_str_count, rb_str_split_m,
rb_str_each_line, rb_str_each_codepoint, rb_str_lstrip_bang,
sym_printable): ditto.
* transcode.c (make_econv_exception): use rb_enc_mbc_to_codepoint()
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-05-19 16:59:22 +00:00
|
|
|
|
|
|
|
/* -> code (and len) or raise exception */
|
2014-06-02 20:23:47 +00:00
|
|
|
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc);
|
* encoding.c (rb_enc_codepoint_len): combine rb_enc_codepoint()
and rb_enc_codelen() in one function to reduce calls.
* encoding.c (rb_enc_codepoint): compatibility function.
* sprintf.c (rb_str_format): use rb_enc_codepoint_len().
* string.c (rb_str_inspect, rb_str_upcase_bang,
rb_str_downcase_bang, rb_str_capitalize_bang,
rb_str_swapcase_bang, trnext, tr_trans, rb_str_delete_bang,
rb_str_squeeze_bang, rb_str_count, rb_str_split_m,
rb_str_each_line, rb_str_each_codepoint, rb_str_lstrip_bang,
sym_printable): ditto.
* transcode.c (make_econv_exception): use rb_enc_mbc_to_codepoint()
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-05-19 16:59:22 +00:00
|
|
|
|
|
|
|
/* prototype for obsolete function */
|
2014-06-02 20:23:47 +00:00
|
|
|
unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc);
|
* encoding.c (rb_enc_codepoint_len): combine rb_enc_codepoint()
and rb_enc_codelen() in one function to reduce calls.
* encoding.c (rb_enc_codepoint): compatibility function.
* sprintf.c (rb_str_format): use rb_enc_codepoint_len().
* string.c (rb_str_inspect, rb_str_upcase_bang,
rb_str_downcase_bang, rb_str_capitalize_bang,
rb_str_swapcase_bang, trnext, tr_trans, rb_str_delete_bang,
rb_str_squeeze_bang, rb_str_count, rb_str_split_m,
rb_str_each_line, rb_str_each_codepoint, rb_str_lstrip_bang,
sym_printable): ditto.
* transcode.c (make_econv_exception): use rb_enc_mbc_to_codepoint()
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-05-19 16:59:22 +00:00
|
|
|
/* overriding macro */
|
|
|
|
#define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc))
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e))
|
2007-12-23 15:19:23 +00:00
|
|
|
|
2007-12-27 06:27:39 +00:00
|
|
|
/* -> codelen>0 or raise exception */
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_codelen(int code, rb_encoding *enc);
|
2013-07-20 03:13:40 +00:00
|
|
|
/* -> 0 for invalid codepoint */
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
|
2013-07-20 03:13:40 +00:00
|
|
|
#define rb_enc_code_to_mbclen(c, enc) ONIGENC_CODE_TO_MBCLEN((enc), (c));
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2008-09-18 12:53:25 +00:00
|
|
|
/* code,ptr,encoding -> write buf */
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC((enc),(c),(UChar*)(buf))
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2008-09-13 18:22:04 +00:00
|
|
|
/* start, ptr, end, encoding -> prev_char */
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
|
2008-09-13 18:22:04 +00:00
|
|
|
/* start, ptr, end, encoding -> next_char */
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
|
|
|
|
#define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
|
|
|
|
#define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n)))
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2008-01-21 19:47:26 +00:00
|
|
|
/* ptr, ptr, encoding -> newline_or_not */
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE((enc),(UChar*)(p),(UChar*)(end))
|
2008-01-21 19:47:26 +00:00
|
|
|
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE((enc),(c),(t))
|
2007-08-25 04:14:26 +00:00
|
|
|
#define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c)
|
2011-04-05 11:34:15 +00:00
|
|
|
#define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA((enc),(c))
|
|
|
|
#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c))
|
|
|
|
#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c))
|
|
|
|
#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c))
|
|
|
|
#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c))
|
|
|
|
#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c))
|
|
|
|
#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c))
|
|
|
|
#define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c))
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2016-02-04 03:16:50 +00:00
|
|
|
static inline int
|
|
|
|
rb_enc_asciicompat_inline(rb_encoding *enc)
|
|
|
|
{
|
|
|
|
return rb_enc_mbminlen(enc)==1 && !rb_enc_dummy_p(enc);
|
|
|
|
}
|
|
|
|
#define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc)
|
2007-09-26 09:39:08 +00:00
|
|
|
|
2014-06-02 20:23:47 +00:00
|
|
|
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc);
|
2016-05-08 17:44:51 +00:00
|
|
|
CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc));
|
|
|
|
CONSTFUNC(int rb_enc_tolower(int c, rb_encoding *enc));
|
2014-06-02 20:23:47 +00:00
|
|
|
ID rb_intern3(const char*, long, rb_encoding*);
|
|
|
|
ID rb_interned_id_p(const char *, long, rb_encoding *);
|
|
|
|
int rb_enc_symname_p(const char*, rb_encoding*);
|
|
|
|
int rb_enc_symname2_p(const char*, long, rb_encoding*);
|
2007-09-26 19:46:58 +00:00
|
|
|
int rb_enc_str_coderange(VALUE);
|
2014-06-02 20:23:47 +00:00
|
|
|
long rb_str_coderange_scan_restartable(const char*, const char*, rb_encoding*, int*);
|
2007-11-25 13:25:34 +00:00
|
|
|
int rb_enc_str_asciionly_p(VALUE);
|
|
|
|
#define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str))
|
2014-06-02 20:23:47 +00:00
|
|
|
VALUE rb_enc_from_encoding(rb_encoding *enc);
|
2016-05-08 17:44:51 +00:00
|
|
|
PUREFUNC(int rb_enc_unicode_p(rb_encoding *enc));
|
2007-12-22 23:47:18 +00:00
|
|
|
rb_encoding *rb_ascii8bit_encoding(void);
|
2007-12-21 06:59:48 +00:00
|
|
|
rb_encoding *rb_utf8_encoding(void);
|
2008-01-23 16:03:29 +00:00
|
|
|
rb_encoding *rb_usascii_encoding(void);
|
2007-12-28 10:12:13 +00:00
|
|
|
rb_encoding *rb_locale_encoding(void);
|
2008-06-16 21:28:03 +00:00
|
|
|
rb_encoding *rb_filesystem_encoding(void);
|
2007-12-01 14:05:53 +00:00
|
|
|
rb_encoding *rb_default_external_encoding(void);
|
2008-10-07 17:39:44 +00:00
|
|
|
rb_encoding *rb_default_internal_encoding(void);
|
2013-08-30 15:25:26 +00:00
|
|
|
#ifndef rb_ascii8bit_encindex
|
2016-05-08 17:44:51 +00:00
|
|
|
CONSTFUNC(int rb_ascii8bit_encindex(void));
|
2013-08-30 15:25:26 +00:00
|
|
|
#endif
|
|
|
|
#ifndef rb_utf8_encindex
|
2016-05-08 17:44:51 +00:00
|
|
|
CONSTFUNC(int rb_utf8_encindex(void));
|
2013-08-30 15:25:26 +00:00
|
|
|
#endif
|
|
|
|
#ifndef rb_usascii_encindex
|
2016-05-08 17:44:51 +00:00
|
|
|
CONSTFUNC(int rb_usascii_encindex(void));
|
2013-08-30 15:25:26 +00:00
|
|
|
#endif
|
2010-05-27 14:47:16 +00:00
|
|
|
int rb_locale_encindex(void);
|
|
|
|
int rb_filesystem_encindex(void);
|
2007-12-01 14:05:53 +00:00
|
|
|
VALUE rb_enc_default_external(void);
|
2008-10-07 17:39:44 +00:00
|
|
|
VALUE rb_enc_default_internal(void);
|
2007-12-01 14:05:53 +00:00
|
|
|
void rb_enc_set_default_external(VALUE encoding);
|
2008-10-07 17:39:44 +00:00
|
|
|
void rb_enc_set_default_internal(VALUE encoding);
|
2007-12-21 02:52:23 +00:00
|
|
|
VALUE rb_locale_charmap(VALUE klass);
|
2014-06-02 20:23:47 +00:00
|
|
|
long rb_memsearch(const void*,long,const void*,long,rb_encoding*);
|
|
|
|
char *rb_enc_path_next(const char *,const char *,rb_encoding*);
|
|
|
|
char *rb_enc_path_skip_prefix(const char *,const char *,rb_encoding*);
|
|
|
|
char *rb_enc_path_last_separator(const char *,const char *,rb_encoding*);
|
|
|
|
char *rb_enc_path_end(const char *,const char *,rb_encoding*);
|
|
|
|
const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc);
|
|
|
|
const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc);
|
|
|
|
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc);
|
2014-08-03 01:55:10 +00:00
|
|
|
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc);
|
2007-08-25 04:14:26 +00:00
|
|
|
|
2008-05-19 08:25:03 +00:00
|
|
|
RUBY_EXTERN VALUE rb_cEncoding;
|
|
|
|
|
2008-08-14 14:28:10 +00:00
|
|
|
/* econv stuff */
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
econv_invalid_byte_sequence,
|
|
|
|
econv_undefined_conversion,
|
|
|
|
econv_destination_buffer_full,
|
|
|
|
econv_source_buffer_empty,
|
|
|
|
econv_finished,
|
2008-09-09 16:27:02 +00:00
|
|
|
econv_after_output,
|
2008-09-22 02:47:05 +00:00
|
|
|
econv_incomplete_input
|
2008-08-14 14:28:10 +00:00
|
|
|
} rb_econv_result_t;
|
|
|
|
|
2008-08-26 15:01:11 +00:00
|
|
|
typedef struct rb_econv_t rb_econv_t;
|
2008-08-14 14:28:10 +00:00
|
|
|
|
2008-09-26 10:35:00 +00:00
|
|
|
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts);
|
|
|
|
int rb_econv_has_convpath_p(const char* from_encoding, const char* to_encoding);
|
2008-08-24 08:39:09 +00:00
|
|
|
|
2011-04-26 15:55:21 +00:00
|
|
|
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags);
|
2008-09-03 18:18:10 +00:00
|
|
|
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts);
|
2008-08-24 07:20:21 +00:00
|
|
|
|
2008-09-03 15:11:46 +00:00
|
|
|
rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags);
|
2008-09-03 18:18:10 +00:00
|
|
|
rb_econv_t *rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts);
|
|
|
|
|
2008-08-14 14:28:10 +00:00
|
|
|
rb_econv_result_t rb_econv_convert(rb_econv_t *ec,
|
2008-08-14 15:56:39 +00:00
|
|
|
const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end,
|
|
|
|
unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end,
|
2008-08-14 14:28:10 +00:00
|
|
|
int flags);
|
2008-08-17 04:25:56 +00:00
|
|
|
void rb_econv_close(rb_econv_t *ec);
|
2008-08-15 11:02:07 +00:00
|
|
|
|
2008-09-03 16:34:11 +00:00
|
|
|
/* result: 0:success -1:failure */
|
2008-09-07 17:08:38 +00:00
|
|
|
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname);
|
2008-09-03 16:34:11 +00:00
|
|
|
|
2008-09-08 17:23:37 +00:00
|
|
|
/* result: 0:success -1:failure */
|
|
|
|
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name);
|
|
|
|
int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name);
|
|
|
|
|
2008-09-03 15:11:46 +00:00
|
|
|
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags);
|
2008-08-24 02:42:37 +00:00
|
|
|
|
2008-08-16 05:32:42 +00:00
|
|
|
/* result: 0:success -1:failure */
|
|
|
|
int rb_econv_insert_output(rb_econv_t *ec,
|
|
|
|
const unsigned char *str, size_t len, const char *str_encoding);
|
|
|
|
|
|
|
|
/* encoding that rb_econv_insert_output doesn't need conversion */
|
|
|
|
const char *rb_econv_encoding_to_insert_output(rb_econv_t *ec);
|
2008-08-15 11:02:07 +00:00
|
|
|
|
2008-08-16 15:04:39 +00:00
|
|
|
/* raise an error if the last rb_econv_convert is error */
|
|
|
|
void rb_econv_check_error(rb_econv_t *ec);
|
|
|
|
|
2008-12-26 05:04:39 +00:00
|
|
|
/* returns an exception object or nil */
|
|
|
|
VALUE rb_econv_make_exception(rb_econv_t *ec);
|
|
|
|
|
2008-08-17 04:25:56 +00:00
|
|
|
int rb_econv_putbackable(rb_econv_t *ec);
|
|
|
|
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n);
|
2008-08-14 14:28:10 +00:00
|
|
|
|
2008-09-08 14:33:17 +00:00
|
|
|
/* returns the corresponding ASCII compatible encoding for encname,
|
|
|
|
* or NULL if encname is not ASCII incompatible encoding. */
|
|
|
|
const char *rb_econv_asciicompat_encoding(const char *encname);
|
2008-08-18 12:06:42 +00:00
|
|
|
|
2008-08-24 03:22:43 +00:00
|
|
|
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags);
|
|
|
|
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags);
|
|
|
|
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags);
|
|
|
|
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags);
|
2013-09-06 02:45:50 +00:00
|
|
|
VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags);
|
2008-08-18 12:06:42 +00:00
|
|
|
|
2008-08-22 16:44:00 +00:00
|
|
|
void rb_econv_binmode(rb_econv_t *ec);
|
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
enum ruby_econv_flag_type {
|
2008-08-14 14:48:41 +00:00
|
|
|
/* flags for rb_econv_open */
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_ERROR_HANDLER_MASK = 0x000000ff,
|
2008-08-23 06:02:58 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_INVALID_MASK = 0x0000000f,
|
|
|
|
RUBY_ECONV_INVALID_REPLACE = 0x00000002,
|
2008-09-06 15:39:00 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_UNDEF_MASK = 0x000000f0,
|
|
|
|
RUBY_ECONV_UNDEF_REPLACE = 0x00000020,
|
|
|
|
RUBY_ECONV_UNDEF_HEX_CHARREF = 0x00000030,
|
2008-09-06 15:39:00 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_DECORATOR_MASK = 0x0000ff00,
|
|
|
|
RUBY_ECONV_NEWLINE_DECORATOR_MASK = 0x00003f00,
|
|
|
|
RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK = 0x00000f00,
|
|
|
|
RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK = 0x00003000,
|
2008-08-23 06:02:58 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR = 0x00000100,
|
|
|
|
RUBY_ECONV_CRLF_NEWLINE_DECORATOR = 0x00001000,
|
|
|
|
RUBY_ECONV_CR_NEWLINE_DECORATOR = 0x00002000,
|
|
|
|
RUBY_ECONV_XML_TEXT_DECORATOR = 0x00004000,
|
|
|
|
RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR = 0x00008000,
|
2008-09-09 12:22:43 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_STATEFUL_DECORATOR_MASK = 0x00f00000,
|
|
|
|
RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR = 0x00100000,
|
2008-08-14 14:48:41 +00:00
|
|
|
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR =
|
2011-04-26 15:55:21 +00:00
|
|
|
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_CRLF_NEWLINE_DECORATOR,
|
2011-04-26 15:55:21 +00:00
|
|
|
#else
|
2015-09-13 02:03:31 +00:00
|
|
|
0,
|
2011-04-26 15:55:21 +00:00
|
|
|
#endif
|
2015-09-13 02:03:31 +00:00
|
|
|
#define ECONV_ERROR_HANDLER_MASK RUBY_ECONV_ERROR_HANDLER_MASK
|
|
|
|
#define ECONV_INVALID_MASK RUBY_ECONV_INVALID_MASK
|
|
|
|
#define ECONV_INVALID_REPLACE RUBY_ECONV_INVALID_REPLACE
|
|
|
|
#define ECONV_UNDEF_MASK RUBY_ECONV_UNDEF_MASK
|
|
|
|
#define ECONV_UNDEF_REPLACE RUBY_ECONV_UNDEF_REPLACE
|
|
|
|
#define ECONV_UNDEF_HEX_CHARREF RUBY_ECONV_UNDEF_HEX_CHARREF
|
|
|
|
#define ECONV_DECORATOR_MASK RUBY_ECONV_DECORATOR_MASK
|
|
|
|
#define ECONV_NEWLINE_DECORATOR_MASK RUBY_ECONV_NEWLINE_DECORATOR_MASK
|
|
|
|
#define ECONV_NEWLINE_DECORATOR_READ_MASK RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
|
|
|
|
#define ECONV_NEWLINE_DECORATOR_WRITE_MASK RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
|
|
|
|
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
|
|
|
|
#define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR
|
|
|
|
#define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR
|
|
|
|
#define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR
|
|
|
|
#define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
|
|
|
|
#define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK
|
|
|
|
#define ECONV_XML_ATTR_QUOTE_DECORATOR RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
|
|
|
|
#define ECONV_DEFAULT_NEWLINE_DECORATOR RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
|
2008-08-26 12:55:14 +00:00
|
|
|
/* end of flags for rb_econv_open */
|
|
|
|
|
2008-08-14 14:48:41 +00:00
|
|
|
/* flags for rb_econv_convert */
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_PARTIAL_INPUT = 0x00010000,
|
|
|
|
RUBY_ECONV_AFTER_OUTPUT = 0x00020000,
|
|
|
|
#define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT
|
|
|
|
#define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT
|
2008-08-26 12:55:14 +00:00
|
|
|
/* end of flags for rb_econv_convert */
|
2015-09-13 02:03:31 +00:00
|
|
|
RUBY_ECONV_FLAGS_PLACEHOLDER};
|
2008-08-14 14:48:41 +00:00
|
|
|
|
2013-04-05 10:29:38 +00:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2010-07-21 21:38:25 +00:00
|
|
|
|
2010-05-25 04:26:50 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
#if 0
|
|
|
|
{ /* satisfy cc-mode */
|
|
|
|
#endif
|
|
|
|
} /* extern "C" { */
|
|
|
|
#endif
|
|
|
|
|
2007-08-25 04:14:26 +00:00
|
|
|
#endif /* RUBY_ENCODING_H */
|