oniguruma.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. #ifndef ONIGURUMA_H
  2. #define ONIGURUMA_H
  3. /**********************************************************************
  4. oniguruma.h - Oniguruma (regular expression library)
  5. **********************************************************************/
  6. /*-
  7. * Copyright (c) 2002-2009 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. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #define ONIGURUMA
  35. #define ONIGURUMA_VERSION_MAJOR 5
  36. #define ONIGURUMA_VERSION_MINOR 9
  37. #define ONIGURUMA_VERSION_TEENY 5
  38. #ifdef __cplusplus
  39. # ifndef HAVE_PROTOTYPES
  40. # define HAVE_PROTOTYPES 1
  41. # endif
  42. # ifndef HAVE_STDARG_PROTOTYPES
  43. # define HAVE_STDARG_PROTOTYPES 1
  44. # endif
  45. #endif
  46. /* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
  47. #if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
  48. # ifndef HAVE_STDARG_PROTOTYPES
  49. # define HAVE_STDARG_PROTOTYPES 1
  50. # endif
  51. #endif
  52. #ifdef HAVE_STDARG_H
  53. # ifndef HAVE_STDARG_PROTOTYPES
  54. # define HAVE_STDARG_PROTOTYPES 1
  55. # endif
  56. #endif
  57. #ifndef P_
  58. #if defined(__STDC__) || defined(_WIN32)
  59. # define P_(args) args
  60. #else
  61. # define P_(args) ()
  62. #endif
  63. #endif
  64. #ifndef PV_
  65. #ifdef HAVE_STDARG_PROTOTYPES
  66. # define PV_(args) args
  67. #else
  68. # define PV_(args) ()
  69. #endif
  70. #endif
  71. #ifndef ONIG_EXTERN
  72. #if defined(_WIN32) && !defined(__GNUC__)
  73. #if defined(EXPORT) || defined(RUBY_EXPORT)
  74. #define ONIG_EXTERN extern __declspec(dllexport)
  75. #else
  76. #define ONIG_EXTERN extern __declspec(dllimport)
  77. #endif
  78. #endif
  79. #endif
  80. #ifndef ONIG_EXTERN
  81. #define ONIG_EXTERN extern
  82. #endif
  83. /* PART: character encoding */
  84. #ifndef ONIG_ESCAPE_UCHAR_COLLISION
  85. #define UChar OnigUChar
  86. #endif
  87. #ifdef _WIN32
  88. # include <windows.h>
  89. typedef ULONG_PTR OnigCodePoint;
  90. #else
  91. typedef unsigned long OnigCodePoint;
  92. #endif
  93. typedef unsigned char OnigUChar;
  94. typedef unsigned int OnigCtype;
  95. typedef unsigned int OnigDistance;
  96. #define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
  97. typedef unsigned int OnigCaseFoldType; /* case fold flag */
  98. ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
  99. /* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */
  100. /* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */
  101. #define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20)
  102. #define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30)
  103. #define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
  104. #define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag
  105. #define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3
  106. #define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13
  107. /* 13 => Unicode:0x1ffc */
  108. /* code range */
  109. #define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0])
  110. #define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1]
  111. #define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2]
  112. typedef struct {
  113. int byte_len; /* argument(original) character(s) byte length */
  114. int code_len; /* number of code */
  115. OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
  116. } OnigCaseFoldCodeItem;
  117. typedef struct {
  118. OnigCodePoint esc;
  119. OnigCodePoint anychar;
  120. OnigCodePoint anytime;
  121. OnigCodePoint zero_or_one_time;
  122. OnigCodePoint one_or_more_time;
  123. OnigCodePoint anychar_anytime;
  124. } OnigMetaCharTableType;
  125. typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
  126. typedef struct OnigEncodingTypeST {
  127. int (*mbc_enc_len)(const OnigUChar* p);
  128. const char* name;
  129. int max_enc_len;
  130. int min_enc_len;
  131. int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
  132. OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
  133. int (*code_to_mbclen)(OnigCodePoint code);
  134. int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
  135. int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
  136. int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg);
  137. int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]);
  138. int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
  139. int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype);
  140. int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]);
  141. OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
  142. int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
  143. } OnigEncodingType;
  144. typedef OnigEncodingType* OnigEncoding;
  145. ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
  146. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_1;
  147. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_2;
  148. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_3;
  149. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_4;
  150. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_5;
  151. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_6;
  152. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_7;
  153. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_8;
  154. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_9;
  155. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_10;
  156. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_11;
  157. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_13;
  158. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_14;
  159. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_15;
  160. ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_16;
  161. ONIG_EXTERN OnigEncodingType OnigEncodingUTF8;
  162. ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
  163. ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
  164. ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
  165. ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
  166. ONIG_EXTERN OnigEncodingType OnigEncodingEUC_JP;
  167. ONIG_EXTERN OnigEncodingType OnigEncodingEUC_TW;
  168. ONIG_EXTERN OnigEncodingType OnigEncodingEUC_KR;
  169. ONIG_EXTERN OnigEncodingType OnigEncodingEUC_CN;
  170. ONIG_EXTERN OnigEncodingType OnigEncodingSJIS;
  171. ONIG_EXTERN OnigEncodingType OnigEncodingKOI8;
  172. ONIG_EXTERN OnigEncodingType OnigEncodingKOI8_R;
  173. ONIG_EXTERN OnigEncodingType OnigEncodingCP1251;
  174. ONIG_EXTERN OnigEncodingType OnigEncodingBIG5;
  175. ONIG_EXTERN OnigEncodingType OnigEncodingGB18030;
  176. #define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
  177. #define ONIG_ENCODING_ISO_8859_1 (&OnigEncodingISO_8859_1)
  178. #define ONIG_ENCODING_ISO_8859_2 (&OnigEncodingISO_8859_2)
  179. #define ONIG_ENCODING_ISO_8859_3 (&OnigEncodingISO_8859_3)
  180. #define ONIG_ENCODING_ISO_8859_4 (&OnigEncodingISO_8859_4)
  181. #define ONIG_ENCODING_ISO_8859_5 (&OnigEncodingISO_8859_5)
  182. #define ONIG_ENCODING_ISO_8859_6 (&OnigEncodingISO_8859_6)
  183. #define ONIG_ENCODING_ISO_8859_7 (&OnigEncodingISO_8859_7)
  184. #define ONIG_ENCODING_ISO_8859_8 (&OnigEncodingISO_8859_8)
  185. #define ONIG_ENCODING_ISO_8859_9 (&OnigEncodingISO_8859_9)
  186. #define ONIG_ENCODING_ISO_8859_10 (&OnigEncodingISO_8859_10)
  187. #define ONIG_ENCODING_ISO_8859_11 (&OnigEncodingISO_8859_11)
  188. #define ONIG_ENCODING_ISO_8859_13 (&OnigEncodingISO_8859_13)
  189. #define ONIG_ENCODING_ISO_8859_14 (&OnigEncodingISO_8859_14)
  190. #define ONIG_ENCODING_ISO_8859_15 (&OnigEncodingISO_8859_15)
  191. #define ONIG_ENCODING_ISO_8859_16 (&OnigEncodingISO_8859_16)
  192. #define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8)
  193. #define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE)
  194. #define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE)
  195. #define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE)
  196. #define ONIG_ENCODING_UTF32_LE (&OnigEncodingUTF32_LE)
  197. #define ONIG_ENCODING_EUC_JP (&OnigEncodingEUC_JP)
  198. #define ONIG_ENCODING_EUC_TW (&OnigEncodingEUC_TW)
  199. #define ONIG_ENCODING_EUC_KR (&OnigEncodingEUC_KR)
  200. #define ONIG_ENCODING_EUC_CN (&OnigEncodingEUC_CN)
  201. #define ONIG_ENCODING_SJIS (&OnigEncodingSJIS)
  202. #define ONIG_ENCODING_KOI8 (&OnigEncodingKOI8)
  203. #define ONIG_ENCODING_KOI8_R (&OnigEncodingKOI8_R)
  204. #define ONIG_ENCODING_CP1251 (&OnigEncodingCP1251)
  205. #define ONIG_ENCODING_BIG5 (&OnigEncodingBIG5)
  206. #define ONIG_ENCODING_GB18030 (&OnigEncodingGB18030)
  207. #define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
  208. /* work size */
  209. #define ONIGENC_CODE_TO_MBC_MAXLEN 7
  210. #define ONIGENC_MBC_CASE_FOLD_MAXLEN 18
  211. /* 18: 6(max-byte) * 3(case-fold chars) */
  212. /* character types */
  213. #define ONIGENC_CTYPE_NEWLINE 0
  214. #define ONIGENC_CTYPE_ALPHA 1
  215. #define ONIGENC_CTYPE_BLANK 2
  216. #define ONIGENC_CTYPE_CNTRL 3
  217. #define ONIGENC_CTYPE_DIGIT 4
  218. #define ONIGENC_CTYPE_GRAPH 5
  219. #define ONIGENC_CTYPE_LOWER 6
  220. #define ONIGENC_CTYPE_PRINT 7
  221. #define ONIGENC_CTYPE_PUNCT 8
  222. #define ONIGENC_CTYPE_SPACE 9
  223. #define ONIGENC_CTYPE_UPPER 10
  224. #define ONIGENC_CTYPE_XDIGIT 11
  225. #define ONIGENC_CTYPE_WORD 12
  226. #define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */
  227. #define ONIGENC_CTYPE_ASCII 14
  228. #define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII
  229. #define onig_enc_len(enc,p,end) ONIGENC_MBC_ENC_LEN(enc,p)
  230. #define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
  231. #define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
  232. #define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
  233. #define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
  234. #define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
  235. #define ONIGENC_IS_MBC_WORD(enc,s,end) \
  236. ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
  237. #define ONIGENC_NAME(enc) ((enc)->name)
  238. #define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
  239. (enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf)
  240. #define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
  241. (enc)->is_allowed_reverse_match(s,end)
  242. #define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
  243. (enc)->left_adjust_char_head(start, s)
  244. #define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
  245. (enc)->apply_all_case_fold(case_fold_flag,f,arg)
  246. #define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
  247. (enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs)
  248. #define ONIGENC_STEP_BACK(enc,start,s,n) \
  249. onigenc_step_back((enc),(start),(s),(n))
  250. #define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p)
  251. #define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
  252. #define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
  253. #define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
  254. #define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end))
  255. #define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end))
  256. #define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code)
  257. #define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf)
  258. #define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
  259. (enc)->property_name_to_ctype(enc,p,end)
  260. #define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype)
  261. #define ONIGENC_IS_CODE_NEWLINE(enc,code) \
  262. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
  263. #define ONIGENC_IS_CODE_GRAPH(enc,code) \
  264. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
  265. #define ONIGENC_IS_CODE_PRINT(enc,code) \
  266. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
  267. #define ONIGENC_IS_CODE_ALNUM(enc,code) \
  268. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
  269. #define ONIGENC_IS_CODE_ALPHA(enc,code) \
  270. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
  271. #define ONIGENC_IS_CODE_LOWER(enc,code) \
  272. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
  273. #define ONIGENC_IS_CODE_UPPER(enc,code) \
  274. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
  275. #define ONIGENC_IS_CODE_CNTRL(enc,code) \
  276. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
  277. #define ONIGENC_IS_CODE_PUNCT(enc,code) \
  278. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
  279. #define ONIGENC_IS_CODE_SPACE(enc,code) \
  280. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
  281. #define ONIGENC_IS_CODE_BLANK(enc,code) \
  282. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
  283. #define ONIGENC_IS_CODE_DIGIT(enc,code) \
  284. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
  285. #define ONIGENC_IS_CODE_XDIGIT(enc,code) \
  286. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
  287. #define ONIGENC_IS_CODE_WORD(enc,code) \
  288. ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
  289. #define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
  290. (enc)->get_ctype_code_range(ctype,sbout,ranges)
  291. ONIG_EXTERN
  292. OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
  293. /* encoding API */
  294. ONIG_EXTERN
  295. int onigenc_init P_((void));
  296. ONIG_EXTERN
  297. int onigenc_set_default_encoding P_((OnigEncoding enc));
  298. ONIG_EXTERN
  299. OnigEncoding onigenc_get_default_encoding P_((void));
  300. ONIG_EXTERN
  301. void onigenc_set_default_caseconv_table P_((const OnigUChar* table));
  302. ONIG_EXTERN
  303. OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
  304. ONIG_EXTERN
  305. OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
  306. ONIG_EXTERN
  307. OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
  308. ONIG_EXTERN
  309. OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
  310. ONIG_EXTERN
  311. int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
  312. ONIG_EXTERN
  313. int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
  314. ONIG_EXTERN
  315. int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
  316. /* PART: regular expression */
  317. /* config parameters */
  318. #define ONIG_NREGION 10
  319. #define ONIG_MAX_BACKREF_NUM 1000
  320. #define ONIG_MAX_REPEAT_NUM 100000
  321. #define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000
  322. /* constants */
  323. #define ONIG_MAX_ERROR_MESSAGE_LEN 90
  324. typedef unsigned int OnigOptionType;
  325. #define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE
  326. /* options */
  327. #define ONIG_OPTION_NONE 0U
  328. #define ONIG_OPTION_IGNORECASE 1U
  329. #define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1)
  330. #define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1)
  331. #define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1)
  332. #define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1)
  333. #define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1)
  334. #define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1)
  335. #define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1)
  336. #define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
  337. /* options (search time) */
  338. #define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1)
  339. #define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1)
  340. #define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1)
  341. #define ONIG_OPTION_MAXBIT ONIG_OPTION_POSIX_REGION /* limit */
  342. #define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt))
  343. #define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt))
  344. #define ONIG_IS_OPTION_ON(options,option) ((options) & (option))
  345. /* syntax */
  346. typedef struct {
  347. unsigned int op;
  348. unsigned int op2;
  349. unsigned int behavior;
  350. OnigOptionType options; /* default option */
  351. OnigMetaCharTableType meta_char_table;
  352. } OnigSyntaxType;
  353. ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
  354. ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
  355. ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
  356. ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
  357. ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
  358. ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
  359. ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
  360. ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
  361. ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
  362. ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
  363. /* predefined syntaxes (see regsyntax.c) */
  364. #define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS)
  365. #define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic)
  366. #define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended)
  367. #define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs)
  368. #define ONIG_SYNTAX_GREP (&OnigSyntaxGrep)
  369. #define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex)
  370. #define ONIG_SYNTAX_JAVA (&OnigSyntaxJava)
  371. #define ONIG_SYNTAX_PERL (&OnigSyntaxPerl)
  372. #define ONIG_SYNTAX_PERL_NG (&OnigSyntaxPerl_NG)
  373. #define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby)
  374. /* default syntax */
  375. ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax;
  376. #define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax
  377. /* syntax (operators) */
  378. #define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0)
  379. #define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */
  380. #define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */
  381. #define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3)
  382. #define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */
  383. #define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5)
  384. #define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */
  385. #define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7)
  386. #define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */
  387. #define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */
  388. #define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */
  389. #define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */
  390. #define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */
  391. #define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */
  392. #define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */
  393. #define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */
  394. #define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */
  395. #define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */
  396. #define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */
  397. #define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */
  398. #define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */
  399. #define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */
  400. #define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */
  401. #define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */
  402. #define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */
  403. #define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */
  404. #define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */
  405. #define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */
  406. #define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */
  407. #define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */
  408. #define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */
  409. #define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */
  410. #define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */
  411. #define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsx),(?-imsx) */
  412. #define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imx), (?-imx) */
  413. #define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */
  414. #define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */
  415. #define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */
  416. #define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */
  417. #define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */
  418. #define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */
  419. #define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */
  420. #define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */
  421. #define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */
  422. #define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */
  423. #define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */
  424. #define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */
  425. #define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */
  426. #define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
  427. /* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
  428. #define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */
  429. #define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */
  430. /* syntax (behavior) */
  431. #define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */
  432. #define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */
  433. #define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */
  434. #define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */
  435. #define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */
  436. #define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */
  437. #define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/
  438. #define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */
  439. #define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */
  440. #define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */
  441. #define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */
  442. /* syntax (behavior) in char class [...] */
  443. #define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */
  444. #define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */
  445. #define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22)
  446. #define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */
  447. /* syntax (behavior) warning */
  448. #define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */
  449. #define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */
  450. /* meta character specifiers (onig_set_meta_char()) */
  451. #define ONIG_META_CHAR_ESCAPE 0
  452. #define ONIG_META_CHAR_ANYCHAR 1
  453. #define ONIG_META_CHAR_ANYTIME 2
  454. #define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3
  455. #define ONIG_META_CHAR_ONE_OR_MORE_TIME 4
  456. #define ONIG_META_CHAR_ANYCHAR_ANYTIME 5
  457. #define ONIG_INEFFECTIVE_META_CHAR 0
  458. /* error codes */
  459. #define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000)
  460. /* normal return */
  461. #define ONIG_NORMAL 0
  462. #define ONIG_MISMATCH -1
  463. #define ONIG_NO_SUPPORT_CONFIG -2
  464. /* internal error */
  465. #define ONIGERR_MEMORY -5
  466. #define ONIGERR_TYPE_BUG -6
  467. #define ONIGERR_PARSER_BUG -11
  468. #define ONIGERR_STACK_BUG -12
  469. #define ONIGERR_UNDEFINED_BYTECODE -13
  470. #define ONIGERR_UNEXPECTED_BYTECODE -14
  471. #define ONIGERR_MATCH_STACK_LIMIT_OVER -15
  472. #define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21
  473. #define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22
  474. /* general error */
  475. #define ONIGERR_INVALID_ARGUMENT -30
  476. /* syntax error */
  477. #define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100
  478. #define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101
  479. #define ONIGERR_EMPTY_CHAR_CLASS -102
  480. #define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103
  481. #define ONIGERR_END_PATTERN_AT_ESCAPE -104
  482. #define ONIGERR_END_PATTERN_AT_META -105
  483. #define ONIGERR_END_PATTERN_AT_CONTROL -106
  484. #define ONIGERR_META_CODE_SYNTAX -108
  485. #define ONIGERR_CONTROL_CODE_SYNTAX -109
  486. #define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110
  487. #define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111
  488. #define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112
  489. #define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113
  490. #define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114
  491. #define ONIGERR_NESTED_REPEAT_OPERATOR -115
  492. #define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116
  493. #define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117
  494. #define ONIGERR_END_PATTERN_IN_GROUP -118
  495. #define ONIGERR_UNDEFINED_GROUP_OPTION -119
  496. #define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121
  497. #define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122
  498. #define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123
  499. /* values error (syntax error) */
  500. #define ONIGERR_TOO_BIG_NUMBER -200
  501. #define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201
  502. #define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202
  503. #define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203
  504. #define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204
  505. #define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205
  506. #define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206
  507. #define ONIGERR_TOO_BIG_BACKREF_NUMBER -207
  508. #define ONIGERR_INVALID_BACKREF -208
  509. #define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209
  510. #define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212
  511. #define ONIGERR_EMPTY_GROUP_NAME -214
  512. #define ONIGERR_INVALID_GROUP_NAME -215
  513. #define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216
  514. #define ONIGERR_UNDEFINED_NAME_REFERENCE -217
  515. #define ONIGERR_UNDEFINED_GROUP_REFERENCE -218
  516. #define ONIGERR_MULTIPLEX_DEFINED_NAME -219
  517. #define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220
  518. #define ONIGERR_NEVER_ENDING_RECURSION -221
  519. #define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222
  520. #define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223
  521. #define ONIGERR_INVALID_CODE_POINT_VALUE -400
  522. #define ONIGERR_INVALID_WIDE_CHAR_VALUE -400
  523. #define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401
  524. #define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402
  525. #define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403
  526. /* errors related to thread */
  527. #define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001
  528. /* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
  529. #define ONIG_MAX_CAPTURE_HISTORY_GROUP 31
  530. #define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
  531. ((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
  532. typedef struct OnigCaptureTreeNodeStruct {
  533. int group; /* group number */
  534. int beg;
  535. int end;
  536. int allocated;
  537. int num_childs;
  538. struct OnigCaptureTreeNodeStruct** childs;
  539. } OnigCaptureTreeNode;
  540. /* match result region type */
  541. struct re_registers {
  542. int allocated;
  543. int num_regs;
  544. int* beg;
  545. int* end;
  546. /* extended */
  547. OnigCaptureTreeNode* history_root; /* capture history tree root */
  548. };
  549. /* capture tree traverse */
  550. #define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1
  551. #define ONIG_TRAVERSE_CALLBACK_AT_LAST 2
  552. #define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
  553. ( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
  554. #define ONIG_REGION_NOTPOS -1
  555. typedef struct re_registers OnigRegion;
  556. typedef struct {
  557. OnigEncoding enc;
  558. OnigUChar* par;
  559. OnigUChar* par_end;
  560. } OnigErrorInfo;
  561. typedef struct {
  562. int lower;
  563. int upper;
  564. } OnigRepeatRange;
  565. typedef void (*OnigWarnFunc) P_((const char* s));
  566. extern void onig_null_warn P_((const char* s));
  567. #define ONIG_NULL_WARN onig_null_warn
  568. #define ONIG_CHAR_TABLE_SIZE 256
  569. /* regex_t state */
  570. #define ONIG_STATE_NORMAL 0
  571. #define ONIG_STATE_SEARCHING 1
  572. #define ONIG_STATE_COMPILING -1
  573. #define ONIG_STATE_MODIFY -2
  574. #define ONIG_STATE(reg) \
  575. ((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
  576. typedef struct re_pattern_buffer {
  577. /* common members of BBuf(bytes-buffer) */
  578. unsigned char* p; /* compiled pattern */
  579. unsigned int used; /* used space for p */
  580. unsigned int alloc; /* allocated space for p */
  581. int state; /* normal, searching, compiling */
  582. int num_mem; /* used memory(...) num counted from 1 */
  583. int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */
  584. int num_null_check; /* OP_NULL_CHECK_START/END id counter */
  585. int num_comb_exp_check; /* combination explosion check */
  586. int num_call; /* number of subexp call */
  587. unsigned int capture_history; /* (?@...) flag (1-31) */
  588. unsigned int bt_mem_start; /* need backtrack flag */
  589. unsigned int bt_mem_end; /* need backtrack flag */
  590. int stack_pop_level;
  591. int repeat_range_alloc;
  592. OnigRepeatRange* repeat_range;
  593. OnigEncoding enc;
  594. OnigOptionType options;
  595. OnigSyntaxType* syntax;
  596. OnigCaseFoldType case_fold_flag;
  597. void* name_table;
  598. /* optimization info (string search, char-map and anchors) */
  599. int optimize; /* optimize flag */
  600. int threshold_len; /* search str-length for apply optimize */
  601. int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
  602. OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */
  603. OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */
  604. int sub_anchor; /* start-anchor for exact or map */
  605. unsigned char *exact;
  606. unsigned char *exact_end;
  607. unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
  608. int *int_map; /* BM skip for exact_len > 255 */
  609. int *int_map_backward; /* BM skip for backward search */
  610. OnigDistance dmin; /* min-distance of exact or map */
  611. OnigDistance dmax; /* max-distance of exact or map */
  612. /* regex_t link chain */
  613. struct re_pattern_buffer* chain; /* escape compile-conflict */
  614. } OnigRegexType;
  615. typedef OnigRegexType* OnigRegex;
  616. #ifndef ONIG_ESCAPE_REGEX_T_COLLISION
  617. typedef OnigRegexType regex_t;
  618. #endif
  619. typedef struct {
  620. int num_of_elements;
  621. OnigEncoding pattern_enc;
  622. OnigEncoding target_enc;
  623. OnigSyntaxType* syntax;
  624. OnigOptionType option;
  625. OnigCaseFoldType case_fold_flag;
  626. } OnigCompileInfo;
  627. /* Oniguruma Native API */
  628. ONIG_EXTERN
  629. int onig_init P_((void));
  630. ONIG_EXTERN
  631. int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
  632. ONIG_EXTERN
  633. void onig_set_warn_func P_((OnigWarnFunc f));
  634. ONIG_EXTERN
  635. void onig_set_verb_warn_func P_((OnigWarnFunc f));
  636. ONIG_EXTERN
  637. int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
  638. ONIG_EXTERN
  639. int onig_reg_init P_((regex_t* reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, OnigSyntaxType* syntax));
  640. int onig_new_without_alloc P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
  641. ONIG_EXTERN
  642. int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
  643. ONIG_EXTERN
  644. void onig_free P_((OnigRegex));
  645. ONIG_EXTERN
  646. void onig_free_body P_((OnigRegex));
  647. ONIG_EXTERN
  648. int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
  649. ONIG_EXTERN
  650. int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
  651. ONIG_EXTERN
  652. int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
  653. ONIG_EXTERN
  654. int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
  655. ONIG_EXTERN
  656. OnigRegion* onig_region_new P_((void));
  657. ONIG_EXTERN
  658. void onig_region_init P_((OnigRegion* region));
  659. ONIG_EXTERN
  660. void onig_region_free P_((OnigRegion* region, int free_self));
  661. ONIG_EXTERN
  662. void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
  663. ONIG_EXTERN
  664. void onig_region_clear P_((OnigRegion* region));
  665. ONIG_EXTERN
  666. int onig_region_resize P_((OnigRegion* region, int n));
  667. ONIG_EXTERN
  668. int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
  669. ONIG_EXTERN
  670. int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
  671. ONIG_EXTERN
  672. int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
  673. ONIG_EXTERN
  674. int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
  675. ONIG_EXTERN
  676. int onig_number_of_names P_((OnigRegex reg));
  677. ONIG_EXTERN
  678. int onig_number_of_captures P_((OnigRegex reg));
  679. ONIG_EXTERN
  680. int onig_number_of_capture_histories P_((OnigRegex reg));
  681. ONIG_EXTERN
  682. OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
  683. ONIG_EXTERN
  684. int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
  685. ONIG_EXTERN
  686. int onig_noname_group_capture_is_active P_((OnigRegex reg));
  687. ONIG_EXTERN
  688. OnigEncoding onig_get_encoding P_((OnigRegex reg));
  689. ONIG_EXTERN
  690. OnigOptionType onig_get_options P_((OnigRegex reg));
  691. ONIG_EXTERN
  692. OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
  693. ONIG_EXTERN
  694. OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
  695. ONIG_EXTERN
  696. int onig_set_default_syntax P_((OnigSyntaxType* syntax));
  697. ONIG_EXTERN
  698. void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
  699. ONIG_EXTERN
  700. unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
  701. ONIG_EXTERN
  702. unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
  703. ONIG_EXTERN
  704. unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
  705. ONIG_EXTERN
  706. OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
  707. ONIG_EXTERN
  708. void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
  709. ONIG_EXTERN
  710. void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
  711. ONIG_EXTERN
  712. void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
  713. ONIG_EXTERN
  714. void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
  715. ONIG_EXTERN
  716. int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
  717. ONIG_EXTERN
  718. void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
  719. ONIG_EXTERN
  720. OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
  721. ONIG_EXTERN
  722. int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
  723. ONIG_EXTERN
  724. unsigned int onig_get_match_stack_limit_size P_((void));
  725. ONIG_EXTERN
  726. int onig_set_match_stack_limit_size P_((unsigned int size));
  727. ONIG_EXTERN
  728. int onig_end P_((void));
  729. ONIG_EXTERN
  730. const char* onig_version P_((void));
  731. ONIG_EXTERN
  732. const char* onig_copyright P_((void));
  733. #ifdef __cplusplus
  734. }
  735. #endif
  736. #endif /* ONIGURUMA_H */