00001 #ifndef ONIGURUMA_REGENC_H
00002 #define ONIGURUMA_REGENC_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef REGINT_H
00033 #ifndef RUBY_EXTERN
00034 #include "ruby/config.h"
00035 #include "ruby/defines.h"
00036 #endif
00037 #ifdef ONIG_ESCAPE_UCHAR_COLLISION
00038 #undef ONIG_ESCAPE_UCHAR_COLLISION
00039 #endif
00040 #endif
00041 #include "ruby/oniguruma.h"
00042
00043 #if defined __GNUC__ && __GNUC__ >= 4
00044 #pragma GCC visibility push(default)
00045 #endif
00046
00047 typedef struct {
00048 OnigCodePoint from;
00049 OnigCodePoint to;
00050 } OnigPairCaseFoldCodes;
00051
00052
00053 #ifndef NULL
00054 #define NULL ((void* )0)
00055 #endif
00056
00057 #ifndef TRUE
00058 #define TRUE 1
00059 #endif
00060
00061 #ifndef FALSE
00062 #define FALSE 0
00063 #endif
00064
00065 #ifndef ARG_UNUSED
00066 #if defined(__GNUC__)
00067 # define ARG_UNUSED __attribute__ ((unused))
00068 #else
00069 # define ARG_UNUSED
00070 #endif
00071 #endif
00072
00073 #define ONIG_IS_NULL(p) (((void*)(p)) == (void*)0)
00074 #define ONIG_IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
00075 #define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL
00076 #define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val)
00077
00078 #define enclen(enc,p,e) ((enc->max_enc_len == enc->min_enc_len) ? enc->min_enc_len : ONIGENC_MBC_ENC_LEN(enc,p,e))
00079
00080
00081 #define BIT_CTYPE_NEWLINE (1<< ONIGENC_CTYPE_NEWLINE)
00082 #define BIT_CTYPE_ALPHA (1<< ONIGENC_CTYPE_ALPHA)
00083 #define BIT_CTYPE_BLANK (1<< ONIGENC_CTYPE_BLANK)
00084 #define BIT_CTYPE_CNTRL (1<< ONIGENC_CTYPE_CNTRL)
00085 #define BIT_CTYPE_DIGIT (1<< ONIGENC_CTYPE_DIGIT)
00086 #define BIT_CTYPE_GRAPH (1<< ONIGENC_CTYPE_GRAPH)
00087 #define BIT_CTYPE_LOWER (1<< ONIGENC_CTYPE_LOWER)
00088 #define BIT_CTYPE_PRINT (1<< ONIGENC_CTYPE_PRINT)
00089 #define BIT_CTYPE_PUNCT (1<< ONIGENC_CTYPE_PUNCT)
00090 #define BIT_CTYPE_SPACE (1<< ONIGENC_CTYPE_SPACE)
00091 #define BIT_CTYPE_UPPER (1<< ONIGENC_CTYPE_UPPER)
00092 #define BIT_CTYPE_XDIGIT (1<< ONIGENC_CTYPE_XDIGIT)
00093 #define BIT_CTYPE_WORD (1<< ONIGENC_CTYPE_WORD)
00094 #define BIT_CTYPE_ALNUM (1<< ONIGENC_CTYPE_ALNUM)
00095 #define BIT_CTYPE_ASCII (1<< ONIGENC_CTYPE_ASCII)
00096
00097 #define CTYPE_TO_BIT(ctype) (1<<(ctype))
00098 #define CTYPE_IS_WORD_GRAPH_PRINT(ctype) \
00099 ((ctype) == ONIGENC_CTYPE_WORD || (ctype) == ONIGENC_CTYPE_GRAPH ||\
00100 (ctype) == ONIGENC_CTYPE_PRINT)
00101
00102
00103 typedef struct {
00104 const UChar *name;
00105 int ctype;
00106 short int len;
00107 } PosixBracketEntryType;
00108
00109 #define PosixBracketEntryInit(name, ctype) {(const UChar *)name, ctype, (short int)(sizeof(name) - 1)}
00110
00111 #define USE_CRNL_AS_LINE_TERMINATOR
00112 #define USE_UNICODE_PROPERTIES
00113
00114
00115
00116
00117 #define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII
00118
00119
00120 ONIG_EXTERN int onigenc_ascii_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc));
00121 ONIG_EXTERN int onigenc_ascii_get_case_fold_codes_by_str P_((OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[], OnigEncoding enc));
00122 ONIG_EXTERN int onigenc_apply_all_case_fold_with_map P_((int map_size, const OnigPairCaseFoldCodes map[], int ess_tsett_flag, OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
00123 ONIG_EXTERN int onigenc_get_case_fold_codes_by_str_with_map P_((int map_size, const OnigPairCaseFoldCodes map[], int ess_tsett_flag, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
00124 ONIG_EXTERN int onigenc_not_support_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[], OnigEncoding enc));
00125 ONIG_EXTERN int onigenc_is_mbc_newline_0x0a P_((const UChar* p, const UChar* end, OnigEncoding enc));
00126
00127
00128
00129 ONIG_EXTERN int onigenc_ascii_mbc_case_fold P_((OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower, OnigEncoding enc));
00130 ONIG_EXTERN int onigenc_single_byte_mbc_enc_len P_((const UChar* p, const UChar* e, OnigEncoding enc));
00131 ONIG_EXTERN OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end, OnigEncoding enc));
00132 ONIG_EXTERN int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
00133 ONIG_EXTERN int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf, OnigEncoding enc));
00134 ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s, const OnigUChar* end, OnigEncoding enc));
00135 ONIG_EXTERN int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc));
00136 ONIG_EXTERN int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc));
00137 ONIG_EXTERN int onigenc_ascii_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc));
00138
00139
00140 ONIG_EXTERN OnigCodePoint onigenc_mbn_mbc_to_code P_((OnigEncoding enc, const UChar* p, const UChar* end));
00141 ONIG_EXTERN int onigenc_mbn_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower));
00142 ONIG_EXTERN int onigenc_mb2_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
00143 ONIG_EXTERN int onigenc_mb2_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
00144 ONIG_EXTERN int onigenc_minimum_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
00145 ONIG_EXTERN int onigenc_unicode_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
00146 ONIG_EXTERN int onigenc_mb2_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
00147 ONIG_EXTERN int onigenc_mb4_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
00148 ONIG_EXTERN int onigenc_mb4_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
00149 ONIG_EXTERN int onigenc_mb4_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
00150
00151
00152
00153 ONIG_EXTERN int onigenc_unicode_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc));
00154 ONIG_EXTERN int onigenc_utf16_32_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint *sb_out, const OnigCodePoint* ranges[], OnigEncoding enc));
00155 ONIG_EXTERN int onigenc_unicode_ctype_code_range P_((int ctype, const OnigCodePoint* ranges[]));
00156 ONIG_EXTERN int onigenc_unicode_get_case_fold_codes_by_str P_((OnigEncoding enc, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
00157 ONIG_EXTERN int onigenc_unicode_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** pp, const UChar* end, UChar* fold));
00158 ONIG_EXTERN int onigenc_unicode_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc));
00159
00160
00161 #define UTF16_IS_SURROGATE_FIRST(c) (((c) & 0xfc) == 0xd8)
00162 #define UTF16_IS_SURROGATE_SECOND(c) (((c) & 0xfc) == 0xdc)
00163
00164 #define ONIGENC_ISO_8859_1_TO_LOWER_CASE(c) \
00165 OnigEncISO_8859_1_ToLowerCaseTable[c]
00166 #define ONIGENC_ISO_8859_1_TO_UPPER_CASE(c) \
00167 OnigEncISO_8859_1_ToUpperCaseTable[c]
00168
00169 ONIG_EXTERN const UChar OnigEncISO_8859_1_ToLowerCaseTable[];
00170 ONIG_EXTERN const UChar OnigEncISO_8859_1_ToUpperCaseTable[];
00171
00172 ONIG_EXTERN int
00173 onigenc_with_ascii_strncmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii , int n));
00174 ONIG_EXTERN int
00175 onigenc_with_ascii_strnicmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii , int n));
00176 ONIG_EXTERN UChar*
00177 onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n));
00178
00179
00180 extern int onig_is_in_code_range P_((const UChar* p, OnigCodePoint code));
00181
00182 ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;
00183 ONIG_EXTERN const UChar OnigEncAsciiToLowerCaseTable[];
00184 ONIG_EXTERN const UChar OnigEncAsciiToUpperCaseTable[];
00185 ONIG_EXTERN const unsigned short OnigEncAsciiCtypeTable[];
00186
00187 #define ONIGENC_IS_ASCII_CODE(code) ((code) < 0x80)
00188 #define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) OnigEncAsciiToLowerCaseTable[c]
00189 #define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) OnigEncAsciiToUpperCaseTable[c]
00190 #define ONIGENC_IS_ASCII_CODE_CTYPE(code,ctype) \
00191 ((OnigEncAsciiCtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0)
00192 #define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \
00193 (ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_UPPER) ||\
00194 ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_LOWER))
00195
00196
00197 #define ONIGENC_IS_IN_RANGE(code, from, to) \
00198 ((OnigCodePoint )((code) - (from)) <= (OnigCodePoint )((to) - (from)))
00199
00200
00201 #ifdef ONIG_ENC_REGISTER
00202 extern int ONIG_ENC_REGISTER(const char *, OnigEncodingType*);
00203 #define OnigEncodingName(n) encoding_##n
00204 #define OnigEncodingDeclare(n) static OnigEncodingType OnigEncodingName(n)
00205 #define OnigEncodingDefine(f,n) \
00206 OnigEncodingDeclare(n); \
00207 void Init_##f(void) { \
00208 ONIG_ENC_REGISTER(OnigEncodingName(n).name, \
00209 &OnigEncodingName(n)); \
00210 } \
00211 OnigEncodingDeclare(n)
00212 #else
00213 #define OnigEncodingName(n) OnigEncoding##n
00214 #define OnigEncodingDeclare(n) OnigEncodingType OnigEncodingName(n)
00215 #define OnigEncodingDefine(f,n) OnigEncodingDeclare(n)
00216 #endif
00217
00218
00219 #define ENC_REPLICATE(name, orig)
00220 #define ENC_ALIAS(name, orig)
00221 #define ENC_DUMMY(name)
00222
00223 #if defined __GNUC__ && __GNUC__ >= 4
00224 #pragma GCC visibility pop
00225 #endif
00226
00227 #endif
00228