regenc.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef REGENC_H
  2. #define REGENC_H
  3. /**********************************************************************
  4. regenc.h - Oniguruma (regular expression library)
  5. **********************************************************************/
  6. /*-
  7. * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. #ifndef PACKAGE
  32. /* PACKAGE is defined in config.h */
  33. #include "config.h"
  34. #endif
  35. #ifdef ONIG_ESCAPE_UCHAR_COLLISION
  36. #undef ONIG_ESCAPE_UCHAR_COLLISION
  37. #endif
  38. #include "oniguruma.h"
  39. typedef struct {
  40. OnigCodePoint from;
  41. OnigCodePoint to;
  42. } OnigPairCaseFoldCodes;
  43. #ifndef NULL
  44. #define NULL ((void* )0)
  45. #endif
  46. #ifndef TRUE
  47. #define TRUE 1
  48. #endif
  49. #ifndef FALSE
  50. #define FALSE 0
  51. #endif
  52. #ifndef ARG_UNUSED
  53. #if defined(__GNUC__)
  54. # define ARG_UNUSED __attribute__ ((unused))
  55. #else
  56. # define ARG_UNUSED
  57. #endif
  58. #endif
  59. #define ONIG_IS_NULL(p) (((void*)(p)) == (void*)0)
  60. #define ONIG_IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
  61. #define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL
  62. #define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val)
  63. #define enclen(enc,p) ONIGENC_MBC_ENC_LEN(enc,p)
  64. /* character types bit flag */
  65. #define BIT_CTYPE_NEWLINE (1<< ONIGENC_CTYPE_NEWLINE)
  66. #define BIT_CTYPE_ALPHA (1<< ONIGENC_CTYPE_ALPHA)
  67. #define BIT_CTYPE_BLANK (1<< ONIGENC_CTYPE_BLANK)
  68. #define BIT_CTYPE_CNTRL (1<< ONIGENC_CTYPE_CNTRL)
  69. #define BIT_CTYPE_DIGIT (1<< ONIGENC_CTYPE_DIGIT)
  70. #define BIT_CTYPE_GRAPH (1<< ONIGENC_CTYPE_GRAPH)
  71. #define BIT_CTYPE_LOWER (1<< ONIGENC_CTYPE_LOWER)
  72. #define BIT_CTYPE_PRINT (1<< ONIGENC_CTYPE_PRINT)
  73. #define BIT_CTYPE_PUNCT (1<< ONIGENC_CTYPE_PUNCT)
  74. #define BIT_CTYPE_SPACE (1<< ONIGENC_CTYPE_SPACE)
  75. #define BIT_CTYPE_UPPER (1<< ONIGENC_CTYPE_UPPER)
  76. #define BIT_CTYPE_XDIGIT (1<< ONIGENC_CTYPE_XDIGIT)
  77. #define BIT_CTYPE_WORD (1<< ONIGENC_CTYPE_WORD)
  78. #define BIT_CTYPE_ALNUM (1<< ONIGENC_CTYPE_ALNUM)
  79. #define BIT_CTYPE_ASCII (1<< ONIGENC_CTYPE_ASCII)
  80. #define CTYPE_TO_BIT(ctype) (1<<(ctype))
  81. #define CTYPE_IS_WORD_GRAPH_PRINT(ctype) \
  82. ((ctype) == ONIGENC_CTYPE_WORD || (ctype) == ONIGENC_CTYPE_GRAPH ||\
  83. (ctype) == ONIGENC_CTYPE_PRINT)
  84. typedef struct {
  85. UChar *name;
  86. int ctype;
  87. short int len;
  88. } PosixBracketEntryType;
  89. #define USE_CRNL_AS_LINE_TERMINATOR
  90. /* #define USE_CRNL_AS_LINE_TERMINATOR */
  91. #define USE_UNICODE_PROPERTIES
  92. /* #define USE_UNICODE_CASE_FOLD_TURKISH_AZERI */
  93. /* #define USE_UNICODE_ALL_LINE_TERMINATORS */ /* see Unicode.org UTF#18 */
  94. #define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII
  95. /* for encoding system implementation (internal) */
  96. ONIG_EXTERN int onigenc_ascii_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
  97. ONIG_EXTERN int onigenc_ascii_get_case_fold_codes_by_str P_((OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
  98. 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));
  99. 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[]));
  100. ONIG_EXTERN int onigenc_not_support_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]));
  101. ONIG_EXTERN int onigenc_is_mbc_newline_0x0a P_((const UChar* p, const UChar* end));
  102. /* methods for single byte encoding */
  103. ONIG_EXTERN int onigenc_ascii_mbc_case_fold P_((OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower));
  104. ONIG_EXTERN int onigenc_single_byte_mbc_enc_len P_((const UChar* p));
  105. ONIG_EXTERN OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end));
  106. ONIG_EXTERN int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code));
  107. ONIG_EXTERN int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf));
  108. ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s));
  109. ONIG_EXTERN int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end));
  110. ONIG_EXTERN int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end));
  111. /* methods for multi byte encoding */
  112. ONIG_EXTERN OnigCodePoint onigenc_mbn_mbc_to_code P_((OnigEncoding enc, const UChar* p, const UChar* end));
  113. ONIG_EXTERN int onigenc_mbn_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower));
  114. ONIG_EXTERN int onigenc_mb2_code_to_mbclen P_((OnigCodePoint code));
  115. ONIG_EXTERN int onigenc_mb2_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
  116. ONIG_EXTERN int onigenc_minimum_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
  117. ONIG_EXTERN int onigenc_unicode_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
  118. ONIG_EXTERN int onigenc_mb2_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
  119. ONIG_EXTERN int onigenc_mb4_code_to_mbclen P_((OnigCodePoint code));
  120. ONIG_EXTERN int onigenc_mb4_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
  121. ONIG_EXTERN int onigenc_mb4_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
  122. /* in enc/unicode.c */
  123. ONIG_EXTERN int onigenc_unicode_is_code_ctype P_((OnigCodePoint code, unsigned int ctype));
  124. ONIG_EXTERN int onigenc_utf16_32_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint *sb_out, const OnigCodePoint* ranges[]));
  125. ONIG_EXTERN int onigenc_unicode_ctype_code_range P_((int ctype, const OnigCodePoint* ranges[]));
  126. ONIG_EXTERN int onigenc_unicode_get_case_fold_codes_by_str P_((OnigEncoding enc, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
  127. ONIG_EXTERN int onigenc_unicode_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** pp, const UChar* end, UChar* fold));
  128. ONIG_EXTERN int onigenc_unicode_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
  129. #define UTF16_IS_SURROGATE_FIRST(c) (((c) & 0xfc) == 0xd8)
  130. #define UTF16_IS_SURROGATE_SECOND(c) (((c) & 0xfc) == 0xdc)
  131. #define ONIGENC_ISO_8859_1_TO_LOWER_CASE(c) \
  132. OnigEncISO_8859_1_ToLowerCaseTable[c]
  133. #define ONIGENC_ISO_8859_1_TO_UPPER_CASE(c) \
  134. OnigEncISO_8859_1_ToUpperCaseTable[c]
  135. ONIG_EXTERN const UChar OnigEncISO_8859_1_ToLowerCaseTable[];
  136. ONIG_EXTERN const UChar OnigEncISO_8859_1_ToUpperCaseTable[];
  137. ONIG_EXTERN int
  138. onigenc_with_ascii_strncmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii /* ascii */, int n));
  139. ONIG_EXTERN UChar*
  140. onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n));
  141. /* defined in regexec.c, but used in enc/xxx.c */
  142. extern int onig_is_in_code_range P_((const UChar* p, OnigCodePoint code));
  143. ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;
  144. ONIG_EXTERN const UChar OnigEncAsciiToLowerCaseTable[];
  145. ONIG_EXTERN const UChar OnigEncAsciiToUpperCaseTable[];
  146. ONIG_EXTERN const unsigned short OnigEncAsciiCtypeTable[];
  147. #define ONIGENC_IS_ASCII_CODE(code) ((code) < 0x80)
  148. #define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) OnigEncAsciiToLowerCaseTable[c]
  149. #define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) OnigEncAsciiToUpperCaseTable[c]
  150. #define ONIGENC_IS_ASCII_CODE_CTYPE(code,ctype) \
  151. ((OnigEncAsciiCtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0)
  152. #define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \
  153. (ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_UPPER) ||\
  154. ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_LOWER))
  155. #endif /* REGENC_H */