Ruby 1.9.3p327(2012-11-10revision37606)
|
00001 #ifndef ONIGURUMA_REGENC_H 00002 #define ONIGURUMA_REGENC_H 00003 /********************************************************************** 00004 regenc.h - Oniguruma (regular expression library) 00005 **********************************************************************/ 00006 /*- 00007 * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp> 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00025 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00026 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00027 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00028 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00029 * SUCH DAMAGE. 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 #if defined __GNUC__ && __GNUC__ >= 4 00043 #pragma GCC visibility push(default) 00044 #endif 00045 00046 typedef struct { 00047 OnigCodePoint from; 00048 OnigCodePoint to; 00049 } OnigPairCaseFoldCodes; 00050 00051 00052 #ifndef NULL 00053 #define NULL ((void* )0) 00054 #endif 00055 00056 #ifndef TRUE 00057 #define TRUE 1 00058 #endif 00059 00060 #ifndef FALSE 00061 #define FALSE 0 00062 #endif 00063 00064 #ifndef ARG_UNUSED 00065 #if defined(__GNUC__) 00066 # define ARG_UNUSED __attribute__ ((unused)) 00067 #else 00068 # define ARG_UNUSED 00069 #endif 00070 #endif 00071 00072 #define ONIG_IS_NULL(p) (((void*)(p)) == (void*)0) 00073 #define ONIG_IS_NOT_NULL(p) (((void*)(p)) != (void*)0) 00074 #define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL 00075 #define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val) 00076 00077 #define enclen(enc,p,e) ((enc->max_enc_len == enc->min_enc_len) ? enc->min_enc_len : ONIGENC_MBC_ENC_LEN(enc,p,e)) 00078 00079 /* character types bit flag */ 00080 #define BIT_CTYPE_NEWLINE (1<< ONIGENC_CTYPE_NEWLINE) 00081 #define BIT_CTYPE_ALPHA (1<< ONIGENC_CTYPE_ALPHA) 00082 #define BIT_CTYPE_BLANK (1<< ONIGENC_CTYPE_BLANK) 00083 #define BIT_CTYPE_CNTRL (1<< ONIGENC_CTYPE_CNTRL) 00084 #define BIT_CTYPE_DIGIT (1<< ONIGENC_CTYPE_DIGIT) 00085 #define BIT_CTYPE_GRAPH (1<< ONIGENC_CTYPE_GRAPH) 00086 #define BIT_CTYPE_LOWER (1<< ONIGENC_CTYPE_LOWER) 00087 #define BIT_CTYPE_PRINT (1<< ONIGENC_CTYPE_PRINT) 00088 #define BIT_CTYPE_PUNCT (1<< ONIGENC_CTYPE_PUNCT) 00089 #define BIT_CTYPE_SPACE (1<< ONIGENC_CTYPE_SPACE) 00090 #define BIT_CTYPE_UPPER (1<< ONIGENC_CTYPE_UPPER) 00091 #define BIT_CTYPE_XDIGIT (1<< ONIGENC_CTYPE_XDIGIT) 00092 #define BIT_CTYPE_WORD (1<< ONIGENC_CTYPE_WORD) 00093 #define BIT_CTYPE_ALNUM (1<< ONIGENC_CTYPE_ALNUM) 00094 #define BIT_CTYPE_ASCII (1<< ONIGENC_CTYPE_ASCII) 00095 00096 #define CTYPE_TO_BIT(ctype) (1<<(ctype)) 00097 #define CTYPE_IS_WORD_GRAPH_PRINT(ctype) \ 00098 ((ctype) == ONIGENC_CTYPE_WORD || (ctype) == ONIGENC_CTYPE_GRAPH ||\ 00099 (ctype) == ONIGENC_CTYPE_PRINT) 00100 00101 00102 typedef struct { 00103 const UChar *name; 00104 int ctype; 00105 short int len; 00106 } PosixBracketEntryType; 00107 00108 #define PosixBracketEntryInit(name, ctype) {(const UChar *)name, ctype, (short int)(sizeof(name) - 1)} 00109 00110 /* #define USE_CRNL_AS_LINE_TERMINATOR */ 00111 #define USE_UNICODE_PROPERTIES 00112 /* #define USE_UNICODE_CASE_FOLD_TURKISH_AZERI */ 00113 /* #define USE_UNICODE_ALL_LINE_TERMINATORS */ /* see Unicode.org UTF#18 */ 00114 00115 00116 #define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII 00117 00118 /* for encoding system implementation (internal) */ 00119 ONIG_EXTERN int onigenc_ascii_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)); 00120 ONIG_EXTERN int onigenc_ascii_get_case_fold_codes_by_str P_((OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[], OnigEncoding enc)); 00121 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)); 00122 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[])); 00123 ONIG_EXTERN int onigenc_not_support_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[], OnigEncoding enc)); 00124 ONIG_EXTERN int onigenc_is_mbc_newline_0x0a P_((const UChar* p, const UChar* end, OnigEncoding enc)); 00125 00126 00127 /* methods for single byte encoding */ 00128 ONIG_EXTERN int onigenc_ascii_mbc_case_fold P_((OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower, OnigEncoding enc)); 00129 ONIG_EXTERN int onigenc_single_byte_mbc_enc_len P_((const UChar* p, const UChar* e, OnigEncoding enc)); 00130 ONIG_EXTERN OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end, OnigEncoding enc)); 00131 ONIG_EXTERN int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc)); 00132 ONIG_EXTERN int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf, OnigEncoding enc)); 00133 ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s, const OnigUChar* end, OnigEncoding enc)); 00134 ONIG_EXTERN int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc)); 00135 ONIG_EXTERN int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc)); 00136 ONIG_EXTERN int onigenc_ascii_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc)); 00137 00138 /* methods for multi byte encoding */ 00139 ONIG_EXTERN OnigCodePoint onigenc_mbn_mbc_to_code P_((OnigEncoding enc, const UChar* p, const UChar* end)); 00140 ONIG_EXTERN int onigenc_mbn_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower)); 00141 ONIG_EXTERN int onigenc_mb2_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc)); 00142 ONIG_EXTERN int onigenc_mb2_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf)); 00143 ONIG_EXTERN int onigenc_minimum_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end)); 00144 ONIG_EXTERN int onigenc_unicode_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end)); 00145 ONIG_EXTERN int onigenc_mb2_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype)); 00146 ONIG_EXTERN int onigenc_mb4_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc)); 00147 ONIG_EXTERN int onigenc_mb4_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf)); 00148 ONIG_EXTERN int onigenc_mb4_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype)); 00149 00150 00151 /* in enc/unicode.c */ 00152 ONIG_EXTERN int onigenc_unicode_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc)); 00153 ONIG_EXTERN int onigenc_utf16_32_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint *sb_out, const OnigCodePoint* ranges[], OnigEncoding enc)); 00154 ONIG_EXTERN int onigenc_unicode_ctype_code_range P_((int ctype, const OnigCodePoint* ranges[])); 00155 ONIG_EXTERN int onigenc_unicode_get_case_fold_codes_by_str P_((OnigEncoding enc, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[])); 00156 ONIG_EXTERN int onigenc_unicode_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** pp, const UChar* end, UChar* fold)); 00157 ONIG_EXTERN int onigenc_unicode_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)); 00158 00159 00160 #define UTF16_IS_SURROGATE_FIRST(c) (((c) & 0xfc) == 0xd8) 00161 #define UTF16_IS_SURROGATE_SECOND(c) (((c) & 0xfc) == 0xdc) 00162 00163 #define ONIGENC_ISO_8859_1_TO_LOWER_CASE(c) \ 00164 OnigEncISO_8859_1_ToLowerCaseTable[c] 00165 #define ONIGENC_ISO_8859_1_TO_UPPER_CASE(c) \ 00166 OnigEncISO_8859_1_ToUpperCaseTable[c] 00167 00168 ONIG_EXTERN const UChar OnigEncISO_8859_1_ToLowerCaseTable[]; 00169 ONIG_EXTERN const UChar OnigEncISO_8859_1_ToUpperCaseTable[]; 00170 00171 ONIG_EXTERN int 00172 onigenc_with_ascii_strncmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii /* ascii */, int n)); 00173 ONIG_EXTERN UChar* 00174 onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n)); 00175 00176 /* defined in regexec.c, but used in enc/xxx.c */ 00177 extern int onig_is_in_code_range P_((const UChar* p, OnigCodePoint code)); 00178 00179 ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding; 00180 ONIG_EXTERN const UChar OnigEncAsciiToLowerCaseTable[]; 00181 ONIG_EXTERN const UChar OnigEncAsciiToUpperCaseTable[]; 00182 ONIG_EXTERN const unsigned short OnigEncAsciiCtypeTable[]; 00183 00184 #define ONIGENC_IS_ASCII_CODE(code) ((code) < 0x80) 00185 #define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) OnigEncAsciiToLowerCaseTable[c] 00186 #define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) OnigEncAsciiToUpperCaseTable[c] 00187 #define ONIGENC_IS_ASCII_CODE_CTYPE(code,ctype) \ 00188 ((OnigEncAsciiCtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0) 00189 #define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \ 00190 (ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_UPPER) ||\ 00191 ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_LOWER)) 00192 00193 #ifdef ONIG_ENC_REGISTER 00194 extern int ONIG_ENC_REGISTER(const char *, OnigEncodingType*); 00195 #define OnigEncodingName(n) encoding_##n 00196 #define OnigEncodingDeclare(n) static OnigEncodingType OnigEncodingName(n) 00197 #define OnigEncodingDefine(f,n) \ 00198 OnigEncodingDeclare(n); \ 00199 void Init_##f(void) { \ 00200 ONIG_ENC_REGISTER(OnigEncodingName(n).name, \ 00201 &OnigEncodingName(n)); \ 00202 } \ 00203 OnigEncodingDeclare(n) 00204 #else 00205 #define OnigEncodingName(n) OnigEncoding##n 00206 #define OnigEncodingDeclare(n) OnigEncodingType OnigEncodingName(n) 00207 #define OnigEncodingDefine(f,n) OnigEncodingDeclare(n) 00208 #endif 00209 00210 /* macros for define replica encoding and encoding alias */ 00211 #define ENC_REPLICATE(name, orig) 00212 #define ENC_ALIAS(name, orig) 00213 #define ENC_DUMMY(name) 00214 00215 #if defined __GNUC__ && __GNUC__ >= 4 00216 #pragma GCC visibility pop 00217 #endif 00218 00219 #endif /* ONIGURUMA_REGENC_H */ 00220