Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# regenc.h

Go to the documentation of this file.

    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 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 /* character types bit flag */
    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 /* #define USE_CRNL_AS_LINE_TERMINATOR */
    00107 #define USE_UNICODE_PROPERTIES
    00108 /* #define USE_UNICODE_CASE_FOLD_TURKISH_AZERI */
    00109 /* #define USE_UNICODE_ALL_LINE_TERMINATORS */  /* see Unicode.org UTF#18 */
    00110
    00111
    00112 #define ONIG_ENCODING_INIT_DEFAULT           ONIG_ENCODING_ASCII
    00113
    00114 /* for encoding system implementation (internal) */
    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 /* methods for single byte encoding */
    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 /* methods for multi byte encoding */
    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 /* in enc/unicode.c */
    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 /* ascii */, int n));
    00169 ONIG_EXTERN UChar*
    00170 onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n));
    00171
    00172 /* defined in regexec.c, but used in enc/xxx.c */
    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 /* macros for define replica encoding and encoding alias */
    00207 #define ENC_REPLICATE(name, orig)
    00208 #define ENC_ALIAS(name, orig)
    00209 #define ENC_DUMMY(name)
    00210
    00211 #endif /* ONIGURUMA_REGENC_H */
    00212