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