@port-labs/jq-node-bindings 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/binding.gyp +3 -3
  2. package/configure +8 -6
  3. package/deps/jq/.travis.yml +184 -35
  4. package/deps/jq/AUTHORS +31 -30
  5. package/deps/jq/COPYING +2 -2
  6. package/deps/jq/KEYS +8 -0
  7. package/deps/jq/Makefile.am +85 -70
  8. package/deps/jq/NEWS +5 -4
  9. package/deps/jq/README.md +18 -9
  10. package/deps/jq/appveyor.yml +53 -0
  11. package/deps/jq/compile-ios.sh +5 -5
  12. package/deps/jq/config/m4/check-math-func.m4 +7 -2
  13. package/deps/jq/configure.ac +130 -68
  14. package/deps/jq/docs/Rakefile +14 -135
  15. package/deps/jq/docs/Rakefile.manual +49 -0
  16. package/deps/jq/docs/Rakefile.website +76 -0
  17. package/deps/jq/docs/content/2.download/default.yml +115 -39
  18. package/deps/jq/docs/content/3.manual/manual.yml +641 -231
  19. package/deps/jq/docs/content/3.manual/v1.3/manual.yml +130 -130
  20. package/deps/jq/docs/content/3.manual/v1.4/manual.yml +160 -160
  21. package/deps/jq/docs/content/3.manual/v1.5/manual.yml +2878 -0
  22. package/deps/jq/docs/content/3.manual/v1.6/manual.yml +3287 -0
  23. package/deps/jq/docs/content/index/index.yml +28 -6
  24. package/deps/jq/docs/public/.htaccess +2 -2
  25. package/deps/jq/docs/public/css/base.scss +141 -59
  26. package/deps/jq/docs/public/js/manual-search.js +52 -0
  27. package/deps/jq/docs/site.yml +1 -10
  28. package/deps/jq/docs/templates/default.liquid +10 -10
  29. package/deps/jq/docs/templates/index.liquid +45 -32
  30. package/deps/jq/docs/templates/manual.liquid +67 -90
  31. package/deps/jq/docs/templates/shared/_footer.liquid +10 -5
  32. package/deps/jq/docs/templates/shared/_head.liquid +17 -12
  33. package/deps/jq/docs/templates/shared/_navbar.liquid +27 -0
  34. package/deps/jq/jq.1.prebuilt +523 -139
  35. package/deps/jq/modules/oniguruma/AUTHORS +1 -0
  36. package/deps/jq/modules/oniguruma/CMakeLists.txt +86 -0
  37. package/deps/jq/modules/oniguruma/COPYING +28 -0
  38. package/deps/jq/modules/oniguruma/ChangeLog +0 -0
  39. package/deps/jq/modules/oniguruma/HISTORY +2138 -0
  40. package/deps/jq/modules/oniguruma/Makefile.am +33 -0
  41. package/deps/jq/modules/oniguruma/NEWS +0 -0
  42. package/deps/jq/modules/oniguruma/README +189 -0
  43. package/deps/jq/modules/oniguruma/README.ja +195 -0
  44. package/deps/jq/modules/oniguruma/README.md +203 -0
  45. package/deps/jq/modules/oniguruma/cmake/dist.cmake +321 -0
  46. package/deps/jq/modules/oniguruma/compile +348 -0
  47. package/deps/jq/modules/oniguruma/config.guess +1754 -0
  48. package/deps/jq/modules/oniguruma/config.sub +1890 -0
  49. package/deps/jq/modules/oniguruma/configure.ac +87 -0
  50. package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +31 -0
  51. package/deps/jq/modules/oniguruma/depcomp +791 -0
  52. package/deps/jq/modules/oniguruma/dist.info +10 -0
  53. package/deps/jq/modules/oniguruma/doc/API +660 -0
  54. package/deps/jq/modules/oniguruma/doc/API.ja +667 -0
  55. package/deps/jq/modules/oniguruma/doc/FAQ +12 -0
  56. package/deps/jq/modules/oniguruma/doc/FAQ.ja +22 -0
  57. package/deps/jq/modules/oniguruma/doc/RE +436 -0
  58. package/deps/jq/modules/oniguruma/doc/RE.ja +448 -0
  59. package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +698 -0
  60. package/deps/jq/modules/oniguruma/index.html +181 -0
  61. package/deps/jq/modules/oniguruma/index_ja.html +184 -0
  62. package/deps/jq/modules/oniguruma/install-sh +541 -0
  63. package/deps/jq/modules/oniguruma/m4/.whatever +0 -0
  64. package/deps/jq/modules/oniguruma/make_win32.bat +3 -0
  65. package/deps/jq/modules/oniguruma/make_win64.bat +3 -0
  66. package/deps/jq/modules/oniguruma/missing +215 -0
  67. package/deps/jq/modules/oniguruma/onig-config.in +78 -0
  68. package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +13 -0
  69. package/deps/jq/modules/oniguruma/oniguruma.pc.in +14 -0
  70. package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +28 -0
  71. package/deps/jq/modules/oniguruma/sample/Makefile.am +34 -0
  72. package/deps/jq/modules/oniguruma/sample/bug_fix.c +131 -0
  73. package/deps/jq/modules/oniguruma/sample/crnl.c +127 -0
  74. package/deps/jq/modules/oniguruma/sample/encode.c +308 -0
  75. package/deps/jq/modules/oniguruma/sample/listcap.c +110 -0
  76. package/deps/jq/modules/oniguruma/sample/names.c +75 -0
  77. package/deps/jq/modules/oniguruma/sample/posix.c +96 -0
  78. package/deps/jq/modules/oniguruma/sample/scan.c +88 -0
  79. package/deps/jq/modules/oniguruma/sample/simple.c +59 -0
  80. package/deps/jq/modules/oniguruma/sample/sql.c +76 -0
  81. package/deps/jq/modules/oniguruma/sample/syntax.c +76 -0
  82. package/deps/jq/modules/oniguruma/sample/user_property.c +87 -0
  83. package/deps/jq/modules/oniguruma/src/Makefile.am +58 -0
  84. package/deps/jq/modules/oniguruma/src/Makefile.windows +183 -0
  85. package/deps/jq/modules/oniguruma/src/ascii.c +61 -0
  86. package/deps/jq/modules/oniguruma/src/big5.c +190 -0
  87. package/deps/jq/modules/oniguruma/src/config.h.cmake.in +71 -0
  88. package/deps/jq/modules/oniguruma/src/config.h.win32 +84 -0
  89. package/deps/jq/modules/oniguruma/src/config.h.win64 +84 -0
  90. package/deps/jq/modules/oniguruma/src/cp1251.c +203 -0
  91. package/deps/jq/modules/oniguruma/src/euc_jp.c +310 -0
  92. package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +158 -0
  93. package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +27 -0
  94. package/deps/jq/modules/oniguruma/src/euc_kr.c +188 -0
  95. package/deps/jq/modules/oniguruma/src/euc_tw.c +171 -0
  96. package/deps/jq/modules/oniguruma/src/gb18030.c +538 -0
  97. package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +67 -0
  98. package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +55 -0
  99. package/deps/jq/modules/oniguruma/src/iso8859_1.c +275 -0
  100. package/deps/jq/modules/oniguruma/src/iso8859_10.c +242 -0
  101. package/deps/jq/modules/oniguruma/src/iso8859_11.c +99 -0
  102. package/deps/jq/modules/oniguruma/src/iso8859_13.c +231 -0
  103. package/deps/jq/modules/oniguruma/src/iso8859_14.c +244 -0
  104. package/deps/jq/modules/oniguruma/src/iso8859_15.c +238 -0
  105. package/deps/jq/modules/oniguruma/src/iso8859_16.c +240 -0
  106. package/deps/jq/modules/oniguruma/src/iso8859_2.c +238 -0
  107. package/deps/jq/modules/oniguruma/src/iso8859_3.c +238 -0
  108. package/deps/jq/modules/oniguruma/src/iso8859_4.c +240 -0
  109. package/deps/jq/modules/oniguruma/src/iso8859_5.c +229 -0
  110. package/deps/jq/modules/oniguruma/src/iso8859_6.c +99 -0
  111. package/deps/jq/modules/oniguruma/src/iso8859_7.c +225 -0
  112. package/deps/jq/modules/oniguruma/src/iso8859_8.c +99 -0
  113. package/deps/jq/modules/oniguruma/src/iso8859_9.c +231 -0
  114. package/deps/jq/modules/oniguruma/src/koi8.c +253 -0
  115. package/deps/jq/modules/oniguruma/src/koi8_r.c +215 -0
  116. package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +22 -0
  117. package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +306 -0
  118. package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +18 -0
  119. package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +545 -0
  120. package/deps/jq/modules/oniguruma/src/mktable.c +1184 -0
  121. package/deps/jq/modules/oniguruma/src/onig_init.c +45 -0
  122. package/deps/jq/modules/oniguruma/src/oniggnu.h +85 -0
  123. package/deps/jq/modules/oniguruma/src/onigposix.h +169 -0
  124. package/deps/jq/modules/oniguruma/src/oniguruma.h +841 -0
  125. package/deps/jq/modules/oniguruma/src/regcomp.c +6300 -0
  126. package/deps/jq/modules/oniguruma/src/regenc.c +917 -0
  127. package/deps/jq/modules/oniguruma/src/regenc.h +243 -0
  128. package/deps/jq/modules/oniguruma/src/regerror.c +393 -0
  129. package/deps/jq/modules/oniguruma/src/regexec.c +3856 -0
  130. package/deps/jq/modules/oniguruma/src/regext.c +202 -0
  131. package/deps/jq/modules/oniguruma/src/reggnu.c +147 -0
  132. package/deps/jq/modules/oniguruma/src/regint.h +779 -0
  133. package/deps/jq/modules/oniguruma/src/regparse.c +5403 -0
  134. package/deps/jq/modules/oniguruma/src/regparse.h +351 -0
  135. package/deps/jq/modules/oniguruma/src/regposerr.c +105 -0
  136. package/deps/jq/modules/oniguruma/src/regposix.c +306 -0
  137. package/deps/jq/modules/oniguruma/src/regsyntax.c +315 -0
  138. package/deps/jq/modules/oniguruma/src/regtrav.c +76 -0
  139. package/deps/jq/modules/oniguruma/src/regversion.c +57 -0
  140. package/deps/jq/modules/oniguruma/src/sjis.c +341 -0
  141. package/deps/jq/modules/oniguruma/src/sjis_prop.c +158 -0
  142. package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +27 -0
  143. package/deps/jq/modules/oniguruma/src/st.c +589 -0
  144. package/deps/jq/modules/oniguruma/src/st.h +68 -0
  145. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +2250 -0
  146. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +203 -0
  147. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +113 -0
  148. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +1225 -0
  149. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +24742 -0
  150. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +4846 -0
  151. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +2571 -0
  152. package/deps/jq/modules/oniguruma/src/unicode.c +664 -0
  153. package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +2548 -0
  154. package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +203 -0
  155. package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +113 -0
  156. package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1366 -0
  157. package/deps/jq/modules/oniguruma/src/unicode_property_data.c +25306 -0
  158. package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +4940 -0
  159. package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +2854 -0
  160. package/deps/jq/modules/oniguruma/src/utf16_be.c +235 -0
  161. package/deps/jq/modules/oniguruma/src/utf16_le.c +245 -0
  162. package/deps/jq/modules/oniguruma/src/utf32_be.c +194 -0
  163. package/deps/jq/modules/oniguruma/src/utf32_le.c +194 -0
  164. package/deps/jq/modules/oniguruma/src/utf8.c +335 -0
  165. package/deps/jq/modules/oniguruma/test/Makefile.am +28 -0
  166. package/deps/jq/modules/oniguruma/test/testc.c +874 -0
  167. package/deps/jq/modules/oniguruma/test/testu.c +916 -0
  168. package/deps/jq/modules/oniguruma/test-driver +153 -0
  169. package/deps/jq/modules/oniguruma/windows/testc.c +869 -0
  170. package/deps/jq/scripts/crosscompile +2 -1
  171. package/deps/jq/scripts/gen_utf8_tables.py +2 -3
  172. package/deps/jq/scripts/update-website +29 -0
  173. package/deps/jq/scripts/version +7 -2
  174. package/deps/jq/sig/jq-release.key +41 -0
  175. package/deps/jq/sig/v1.3/jq-linux-x86.asc +17 -0
  176. package/deps/jq/sig/v1.3/jq-linux-x86_64.asc +17 -0
  177. package/deps/jq/sig/v1.3/jq-osx-x86.asc +17 -0
  178. package/deps/jq/sig/v1.3/jq-osx-x86_64.asc +17 -0
  179. package/deps/jq/sig/v1.3/jq-win32.exe.asc +17 -0
  180. package/deps/jq/sig/v1.3/jq-win64.exe.asc +17 -0
  181. package/deps/jq/sig/v1.3/sha256sum.txt +6 -0
  182. package/deps/jq/sig/v1.4/jq-linux-x86.asc +17 -0
  183. package/deps/jq/sig/v1.4/jq-linux-x86_64.asc +17 -0
  184. package/deps/jq/sig/v1.4/jq-osx-x86.asc +17 -0
  185. package/deps/jq/sig/v1.4/jq-osx-x86_64.asc +17 -0
  186. package/deps/jq/sig/v1.4/jq-solaris11-32.asc +17 -0
  187. package/deps/jq/sig/v1.4/jq-solaris11-64.asc +17 -0
  188. package/deps/jq/sig/v1.4/jq-win32.exe.asc +17 -0
  189. package/deps/jq/sig/v1.4/jq-win64.exe.asc +17 -0
  190. package/deps/jq/sig/v1.4/sha256sum.txt +8 -0
  191. package/deps/jq/sig/v1.5/jq-linux32-no-oniguruma.asc +17 -0
  192. package/deps/jq/sig/v1.5/jq-linux32.asc +17 -0
  193. package/deps/jq/sig/v1.5/jq-linux64.asc +17 -0
  194. package/deps/jq/sig/v1.5/jq-osx-amd64.asc +17 -0
  195. package/deps/jq/sig/v1.5/jq-win32.exe.asc +17 -0
  196. package/deps/jq/sig/v1.5/jq-win64.exe.asc +17 -0
  197. package/deps/jq/sig/v1.5/sha256sum.txt +5 -0
  198. package/deps/jq/sig/v1.5rc1/jq-linux-x86_64-static.asc +17 -0
  199. package/deps/jq/sig/v1.5rc1/jq-win32.exe.asc +17 -0
  200. package/deps/jq/sig/v1.5rc1/jq-win64.exe.asc +17 -0
  201. package/deps/jq/sig/v1.5rc1/sha256sum.txt +3 -0
  202. package/deps/jq/sig/v1.5rc2/jq-linux-x86.asc +17 -0
  203. package/deps/jq/sig/v1.5rc2/jq-linux-x86_64.asc +17 -0
  204. package/deps/jq/sig/v1.5rc2/jq-osx-x86_64.asc +17 -0
  205. package/deps/jq/sig/v1.5rc2/jq-win32.exe.asc +17 -0
  206. package/deps/jq/sig/v1.5rc2/jq-win64.exe.asc +17 -0
  207. package/deps/jq/sig/v1.5rc2/sha256sum.txt +5 -0
  208. package/deps/jq/sig/v1.6/jq-linux32.asc +16 -0
  209. package/deps/jq/sig/v1.6/jq-linux64.asc +16 -0
  210. package/deps/jq/sig/v1.6/jq-osx-amd64.asc +16 -0
  211. package/deps/jq/sig/v1.6/jq-win32.exe.asc +16 -0
  212. package/deps/jq/sig/v1.6/jq-win64.exe.asc +16 -0
  213. package/deps/jq/sig/v1.6/sha256sum.txt +5 -0
  214. package/deps/jq/{builtin.c → src/builtin.c} +449 -344
  215. package/deps/jq/{builtin.h → src/builtin.h} +0 -0
  216. package/deps/jq/src/builtin.jq +311 -0
  217. package/deps/jq/{bytecode.c → src/bytecode.c} +0 -0
  218. package/deps/jq/{bytecode.h → src/bytecode.h} +0 -0
  219. package/deps/jq/{compile.c → src/compile.c} +213 -37
  220. package/deps/jq/{compile.h → src/compile.h} +7 -2
  221. package/deps/jq/{exec_stack.h → src/exec_stack.h} +0 -0
  222. package/deps/jq/{execute.c → src/execute.c} +127 -24
  223. package/deps/jq/{inject_errors.c → src/inject_errors.c} +0 -0
  224. package/deps/jq/{jq.h → src/jq.h} +13 -2
  225. package/deps/jq/{jq_parser.h → src/jq_parser.h} +0 -0
  226. package/deps/jq/{jq_test.c → src/jq_test.c} +1 -1
  227. package/deps/jq/{jv.c → src/jv.c} +24 -5
  228. package/deps/jq/{jv.h → src/jv.h} +46 -11
  229. package/deps/jq/{jv_alloc.c → src/jv_alloc.c} +0 -0
  230. package/deps/jq/{jv_alloc.h → src/jv_alloc.h} +0 -0
  231. package/deps/jq/{jv_aux.c → src/jv_aux.c} +38 -14
  232. package/deps/jq/{jv_dtoa.c → src/jv_dtoa.c} +4 -5
  233. package/deps/jq/{jv_dtoa.h → src/jv_dtoa.h} +0 -0
  234. package/deps/jq/src/jv_file.c +81 -0
  235. package/deps/jq/{jv_parse.c → src/jv_parse.c} +8 -2
  236. package/deps/jq/{jv_print.c → src/jv_print.c} +80 -27
  237. package/deps/jq/{jv_unicode.c → src/jv_unicode.c} +28 -4
  238. package/deps/jq/{jv_unicode.h → src/jv_unicode.h} +1 -0
  239. package/deps/jq/{jv_utf8_tables.h → src/jv_utf8_tables.h} +0 -0
  240. package/deps/jq/{lexer.c → src/lexer.c} +317 -292
  241. package/deps/jq/{lexer.h → src/lexer.h} +16 -12
  242. package/deps/jq/{lexer.l → src/lexer.l} +5 -4
  243. package/deps/jq/src/libm.h +291 -0
  244. package/deps/jq/{linker.c → src/linker.c} +5 -3
  245. package/deps/jq/{linker.h → src/linker.h} +0 -0
  246. package/deps/jq/{locfile.c → src/locfile.c} +1 -1
  247. package/deps/jq/{locfile.h → src/locfile.h} +0 -0
  248. package/deps/jq/{main.c → src/main.c} +202 -100
  249. package/deps/jq/{opcode_list.h → src/opcode_list.h} +4 -0
  250. package/deps/jq/{parser.c → src/parser.c} +1149 -1069
  251. package/deps/jq/{parser.h → src/parser.h} +28 -24
  252. package/deps/jq/{parser.y → src/parser.y} +108 -52
  253. package/deps/jq/{util.c → src/util.c} +12 -9
  254. package/deps/jq/{util.h → src/util.h} +0 -0
  255. package/deps/jq/tests/base64.test +35 -0
  256. package/deps/jq/tests/base64test +5 -0
  257. package/deps/jq/tests/jq-f-test.sh +4 -0
  258. package/deps/jq/tests/jq.test +305 -21
  259. package/deps/jq/tests/jqtest +1 -1
  260. package/deps/jq/tests/mantest +1 -1
  261. package/deps/jq/tests/onig.test +13 -0
  262. package/deps/jq/tests/onigtest +1 -1
  263. package/deps/jq/tests/optional.test +20 -0
  264. package/deps/jq/tests/optionaltest +5 -0
  265. package/deps/jq/tests/setup +7 -1
  266. package/deps/jq/tests/shtest +133 -29
  267. package/deps/jq/tests/utf8-truncate.jq +3 -0
  268. package/deps/jq/tests/utf8test +10 -0
  269. package/lib/index.js +7 -1
  270. package/package.json +3 -3
  271. package/test/santiy.test.js +24 -0
  272. package/deps/jq/docs/default_manpage.md +0 -22
  273. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +0 -1058
  274. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +0 -9
  275. package/deps/jq/docs/public/bootstrap/css/bootstrap.css +0 -5224
  276. package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +0 -9
  277. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
  278. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
  279. package/deps/jq/docs/public/bootstrap/js/bootstrap.js +0 -2027
  280. package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +0 -6
  281. package/deps/jq/docs/templates/shared/_header.liquid +0 -26
  282. package/deps/jq/jq.1.default +0 -39
  283. package/deps/jq/jv_file.c +0 -49
  284. package/deps/jq/libm.h +0 -160
  285. package/deps/jq/setup.sh +0 -33
  286. package/reports/jest-port-api.xml +0 -35
@@ -0,0 +1,308 @@
1
+ /*
2
+ * encode.c
3
+ */
4
+ #include <stdio.h>
5
+ #include "oniguruma.h"
6
+
7
+ static int
8
+ search(regex_t* reg, unsigned char* str, unsigned char* end)
9
+ {
10
+ int r;
11
+ unsigned char *start, *range;
12
+ OnigRegion *region;
13
+
14
+ region = onig_region_new();
15
+
16
+ start = str;
17
+ range = end;
18
+ r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE);
19
+ if (r >= 0) {
20
+ int i;
21
+
22
+ fprintf(stderr, "match at %d (%s)\n", r,
23
+ ONIGENC_NAME(onig_get_encoding(reg)));
24
+ for (i = 0; i < region->num_regs; i++) {
25
+ fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]);
26
+ }
27
+ }
28
+ else if (r == ONIG_MISMATCH) {
29
+ fprintf(stderr, "search fail (%s)\n",
30
+ ONIGENC_NAME(onig_get_encoding(reg)));
31
+ }
32
+ else { /* error */
33
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
34
+ onig_error_code_to_str(s, r);
35
+ fprintf(stderr, "ERROR: %s\n", s);
36
+ fprintf(stderr, " (%s)\n", ONIGENC_NAME(onig_get_encoding(reg)));
37
+ return -1;
38
+ }
39
+
40
+ onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
41
+ return 0;
42
+ }
43
+
44
+ static int
45
+ exec(OnigEncoding enc, OnigOptionType options,
46
+ char* apattern, char* astr)
47
+ {
48
+ int r;
49
+ unsigned char *end;
50
+ regex_t* reg;
51
+ OnigErrorInfo einfo;
52
+ UChar* pattern = (UChar* )apattern;
53
+ UChar* str = (UChar* )astr;
54
+
55
+ onig_initialize(&enc, 1);
56
+
57
+ r = onig_new(&reg, pattern,
58
+ pattern + onigenc_str_bytelen_null(enc, pattern),
59
+ options, enc, ONIG_SYNTAX_DEFAULT, &einfo);
60
+ if (r != ONIG_NORMAL) {
61
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
62
+ onig_error_code_to_str(s, r, &einfo);
63
+ fprintf(stderr, "ERROR: %s\n", s);
64
+ return -1;
65
+ }
66
+
67
+ end = str + onigenc_str_bytelen_null(enc, str);
68
+ r = search(reg, str, end);
69
+
70
+ onig_free(reg);
71
+ onig_end();
72
+ return 0;
73
+ }
74
+
75
+ static OnigCaseFoldType CF = ONIGENC_CASE_FOLD_MIN;
76
+
77
+ #if 0
78
+ static void
79
+ set_case_fold(OnigCaseFoldType cf)
80
+ {
81
+ CF = cf;
82
+ }
83
+ #endif
84
+
85
+ static int
86
+ exec_deluxe(OnigEncoding pattern_enc, OnigEncoding str_enc,
87
+ OnigOptionType options, char* apattern, char* astr)
88
+ {
89
+ int r;
90
+ unsigned char *end;
91
+ regex_t* reg;
92
+ OnigCompileInfo ci;
93
+ OnigErrorInfo einfo;
94
+ UChar* pattern = (UChar* )apattern;
95
+ UChar* str = (UChar* )astr;
96
+
97
+ onig_initialize(&str_enc, 1);
98
+
99
+ ci.num_of_elements = 5;
100
+ ci.pattern_enc = pattern_enc;
101
+ ci.target_enc = str_enc;
102
+ ci.syntax = ONIG_SYNTAX_DEFAULT;
103
+ ci.option = options;
104
+ ci.case_fold_flag = CF;
105
+
106
+ r = onig_new_deluxe(&reg, pattern,
107
+ pattern + onigenc_str_bytelen_null(pattern_enc, pattern),
108
+ &ci, &einfo);
109
+ if (r != ONIG_NORMAL) {
110
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
111
+ onig_error_code_to_str(s, r, &einfo);
112
+ fprintf(stderr, "ERROR: %s\n", s);
113
+ return -1;
114
+ }
115
+
116
+ end = str + onigenc_str_bytelen_null(str_enc, str);
117
+ r = search(reg, str, end);
118
+
119
+ onig_free(reg);
120
+ onig_end();
121
+ return 0;
122
+ }
123
+
124
+ extern int main(int argc, char* argv[])
125
+ {
126
+ int r;
127
+ /* ISO 8859-1 test */
128
+ static unsigned char str[] = { 0xc7, 0xd6, 0xfe, 0xea, 0xe0, 0xe2, 0x00 };
129
+ static unsigned char pattern[] = { 0xe7, 0xf6, 0xde, '\\', 'w', '+', 0x00 };
130
+
131
+ r = exec(ONIG_ENCODING_SJIS, ONIG_OPTION_NONE,
132
+ "^a\\p{Hiragana}c$", "a\202\274c");
133
+
134
+ r = exec(ONIG_ENCODING_EUC_JP, ONIG_OPTION_NONE,
135
+ "^a\\p{Hiragana}c$", "a\244\276c");
136
+
137
+ r = exec(ONIG_ENCODING_CP1251, ONIG_OPTION_IGNORECASE,
138
+ "aBc", " AbC");
139
+
140
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
141
+ " [a-c\337z] ", " SS ");
142
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
143
+ " [\330-\341] ", " SS ");
144
+
145
+ r = exec(ONIG_ENCODING_ISO_8859_2, ONIG_OPTION_IGNORECASE,
146
+ "\337 ", " Ss ");
147
+ r = exec(ONIG_ENCODING_ISO_8859_2, ONIG_OPTION_IGNORECASE,
148
+ "SS ", " \337 ");
149
+ r = exec(ONIG_ENCODING_ISO_8859_2, ONIG_OPTION_IGNORECASE,
150
+ "\\A\\S\\z", "ss");
151
+
152
+ r = exec(ONIG_ENCODING_ISO_8859_2, ONIG_OPTION_IGNORECASE,
153
+ "[ac]+", "bbbaAaCCC");
154
+
155
+ r = exec(ONIG_ENCODING_ISO_8859_3, ONIG_OPTION_IGNORECASE,
156
+ "[ac]+", "bbbaAaCCC");
157
+ r = exec(ONIG_ENCODING_ISO_8859_4, ONIG_OPTION_IGNORECASE,
158
+ "[ac]+", "bbbaAaCCC");
159
+ r = exec(ONIG_ENCODING_ISO_8859_5, ONIG_OPTION_IGNORECASE,
160
+ "[ac]+", "bbbaAaCCC");
161
+ r = exec(ONIG_ENCODING_ISO_8859_6, ONIG_OPTION_IGNORECASE,
162
+ "[ac]+", "bbbaAaCCC");
163
+ r = exec(ONIG_ENCODING_ISO_8859_7, ONIG_OPTION_IGNORECASE,
164
+ "[ac]+", "bbbaAaCCC");
165
+ r = exec(ONIG_ENCODING_ISO_8859_8, ONIG_OPTION_IGNORECASE,
166
+ "[ac]+", "bbbaAaCCC");
167
+ r = exec(ONIG_ENCODING_ISO_8859_9, ONIG_OPTION_IGNORECASE,
168
+ "[ac]+", "bbbaAaCCC");
169
+ r = exec(ONIG_ENCODING_ISO_8859_10, ONIG_OPTION_IGNORECASE,
170
+ "[ac]+", "bbbaAaCCC");
171
+ r = exec(ONIG_ENCODING_ISO_8859_11, ONIG_OPTION_IGNORECASE,
172
+ "[ac]+", "bbbaAaCCC");
173
+ r = exec(ONIG_ENCODING_ISO_8859_13, ONIG_OPTION_IGNORECASE,
174
+ "[ac]+", "bbbaAaCCC");
175
+ r = exec(ONIG_ENCODING_ISO_8859_14, ONIG_OPTION_IGNORECASE,
176
+ "[ac]+", "bbbaAaCCC");
177
+ r = exec(ONIG_ENCODING_ISO_8859_15, ONIG_OPTION_IGNORECASE,
178
+ (char* )pattern, (char* )str);
179
+ r = exec(ONIG_ENCODING_ISO_8859_16, ONIG_OPTION_IGNORECASE,
180
+ (char* )pattern, (char* )str);
181
+
182
+ r = exec(ONIG_ENCODING_KOI8_R, ONIG_OPTION_NONE, "a+", "bbbaaaccc");
183
+ r = exec(ONIG_ENCODING_EUC_TW, ONIG_OPTION_NONE, "b*a+?c+", "bbbaaaccc");
184
+ r = exec(ONIG_ENCODING_EUC_KR, ONIG_OPTION_NONE, "a+", "bbbaaaccc");
185
+ r = exec(ONIG_ENCODING_EUC_CN, ONIG_OPTION_NONE, "c+", "bbbaaaccc");
186
+ r = exec(ONIG_ENCODING_BIG5, ONIG_OPTION_NONE, "a+", "bbbaaaccc");
187
+
188
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
189
+ "\337", "SS");
190
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
191
+ "SS", "\337");
192
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
193
+ "SSb\337ssc", "a\337bSS\337cd");
194
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
195
+ "[a\337]{0,2}", "aSS");
196
+ r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
197
+ "is", "iss");
198
+
199
+ r = exec_deluxe(ONIG_ENCODING_ASCII, ONIG_ENCODING_UTF16_BE,
200
+ ONIG_OPTION_NONE, "a+",
201
+ "\000b\000a\000a\000a\000c\000c\000\000");
202
+
203
+ r = exec_deluxe(ONIG_ENCODING_ASCII, ONIG_ENCODING_UTF16_LE,
204
+ ONIG_OPTION_NONE, "a+",
205
+ "b\000a\000a\000a\000a\000c\000\000\000");
206
+
207
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_LE,
208
+ ONIG_OPTION_NONE,
209
+ "\000b\000a\000a\000a\000c\000c\000\000",
210
+ "x\000b\000a\000a\000a\000c\000c\000\000\000");
211
+
212
+ r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_BE,
213
+ ONIG_OPTION_IGNORECASE,
214
+ "\337", "\000S\000S\000\000");
215
+
216
+ r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_BE,
217
+ ONIG_OPTION_IGNORECASE,
218
+ "SS", "\000\337\000\000");
219
+
220
+ r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_LE,
221
+ ONIG_OPTION_IGNORECASE,
222
+ "\337", "S\000S\000\000\000");
223
+
224
+ r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF32_BE,
225
+ ONIG_OPTION_IGNORECASE,
226
+ "SS", "\000\000\000\337\000\000\000\000");
227
+
228
+ r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF32_LE,
229
+ ONIG_OPTION_IGNORECASE,
230
+ "\337", "S\000\000\000S\000\000\000\000\000\000\000");
231
+
232
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_NONE,
233
+ "\000[\000[\000:\000a\000l\000n\000u\000m\000:\000]\000]\000+\000\000",
234
+ "\000#\002\120\000a\000Z\012\077\012\076\012\075\000\000");
235
+ /* 0x0a3d == \012\075 : is not alnum */
236
+ /* 0x0a3e == \012\076 : is alnum */
237
+
238
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_NONE,
239
+ "\000\\\000d\000+\000\000",
240
+ "\0003\0001\377\020\377\031\377\032\000\000");
241
+
242
+ r = exec(ONIG_ENCODING_GB18030, ONIG_OPTION_IGNORECASE,
243
+ "(Aa\\d)+", "BaA5Aa0234");
244
+
245
+ r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_BE,
246
+ ONIG_OPTION_NONE,
247
+ "^\\P{Hiragana}\\p{^Hiragana}(\\p{Hiragana}+)$",
248
+ "\060\100\060\240\060\101\060\102\060\226\060\237\000\000");
249
+
250
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
251
+ ONIG_OPTION_IGNORECASE,
252
+ "\000[\000\337\000]\000\000", "\000S\000S\000\000");
253
+
254
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
255
+ ONIG_OPTION_IGNORECASE,
256
+ "\000[\000\337\000]\000\000", "\000s\000S\000\000");
257
+
258
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
259
+ ONIG_OPTION_IGNORECASE,
260
+ "\000^\000[\000\001\000-\377\375\000]\000$\000\000",
261
+ "\000s\000S\000\000");
262
+
263
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
264
+ ONIG_OPTION_IGNORECASE,
265
+ "\000S\000S\000\000",
266
+ "\000S\000T\000\337\000\000");
267
+
268
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
269
+ ONIG_OPTION_IGNORECASE,
270
+ "\000S\000T\000S\000S\000\000",
271
+ "\000S\000t\000s\000S\000\000");
272
+
273
+ {
274
+ UChar pat[] = { 0x1f, 0xfc, 0x00, 0x00 };
275
+ UChar str1[] = { 0x21, 0x26, 0x1f, 0xbe, 0x00, 0x00 };
276
+ UChar str2[] = { 0x1f, 0xf3, 0x00, 0x00 };
277
+
278
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
279
+ ONIG_OPTION_IGNORECASE,
280
+ (char* )pat, (char* )str1);
281
+
282
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
283
+ ONIG_OPTION_IGNORECASE,
284
+ (char* )pat, (char* )str2);
285
+ }
286
+
287
+ #if 0
288
+ /* You should define USE_UNICODE_CASE_FOLD_TURKISH_AZERI in regenc.h. */
289
+
290
+ set_case_fold(ONIGENC_CASE_FOLD_TURKISH_AZERI);
291
+
292
+ r = exec_deluxe(ONIG_ENCODING_UTF8, ONIG_ENCODING_UTF8,
293
+ ONIG_OPTION_IGNORECASE,
294
+ "Ii", "\304\261\304\260");
295
+
296
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
297
+ ONIG_OPTION_IGNORECASE,
298
+ "\000I\000i\000\000", "\001\061\001\060\000\000");
299
+
300
+ r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
301
+ ONIG_OPTION_IGNORECASE,
302
+ "\001\061\001\060\000\000", "\000I\000i\000\000");
303
+
304
+ set_case_fold(ONIGENC_CASE_FOLD_MIN);
305
+ #endif
306
+
307
+ return r;
308
+ }
@@ -0,0 +1,110 @@
1
+ /*
2
+ * listcap.c
3
+ *
4
+ * capture history (?@...) sample.
5
+ */
6
+ #include <stdio.h>
7
+ #include <string.h>
8
+ #include "oniguruma.h"
9
+
10
+ static int
11
+ node_callback(int group, int beg, int end, int level, int at, void* arg)
12
+ {
13
+ int i;
14
+
15
+ if (at != ONIG_TRAVERSE_CALLBACK_AT_FIRST)
16
+ return -1; /* error */
17
+
18
+ /* indent */
19
+ for (i = 0; i < level * 2; i++)
20
+ fputc(' ', stderr);
21
+
22
+ fprintf(stderr, "%d: (%d-%d)\n", group, beg, end);
23
+ return 0;
24
+ }
25
+
26
+ extern int ex(unsigned char* str, unsigned char* pattern,
27
+ OnigSyntaxType* syntax)
28
+ {
29
+ int r;
30
+ unsigned char *start, *range, *end;
31
+ regex_t* reg;
32
+ OnigErrorInfo einfo;
33
+ OnigRegion *region;
34
+
35
+ r = onig_new(&reg, pattern, pattern + strlen((char* )pattern),
36
+ ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, syntax, &einfo);
37
+ if (r != ONIG_NORMAL) {
38
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
39
+ onig_error_code_to_str(s, r, &einfo);
40
+ fprintf(stderr, "ERROR: %s\n", s);
41
+ return -1;
42
+ }
43
+
44
+ fprintf(stderr, "number of captures: %d\n", onig_number_of_captures(reg));
45
+ fprintf(stderr, "number of capture histories: %d\n",
46
+ onig_number_of_capture_histories(reg));
47
+
48
+ region = onig_region_new();
49
+
50
+ end = str + strlen((char* )str);
51
+ start = str;
52
+ range = end;
53
+ r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE);
54
+ if (r >= 0) {
55
+ int i;
56
+
57
+ fprintf(stderr, "match at %d\n", r);
58
+ for (i = 0; i < region->num_regs; i++) {
59
+ fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]);
60
+ }
61
+ fprintf(stderr, "\n");
62
+
63
+ r = onig_capture_tree_traverse(region, ONIG_TRAVERSE_CALLBACK_AT_FIRST,
64
+ node_callback, (void* )0);
65
+ }
66
+ else if (r == ONIG_MISMATCH) {
67
+ fprintf(stderr, "search fail\n");
68
+ }
69
+ else { /* error */
70
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
71
+ onig_error_code_to_str(s, r);
72
+ return -1;
73
+ }
74
+
75
+ onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
76
+ onig_free(reg);
77
+ return 0;
78
+ }
79
+
80
+
81
+ extern int main(int argc, char* argv[])
82
+ {
83
+ int r;
84
+ OnigSyntaxType syn;
85
+
86
+ static UChar* str1 = (UChar* )"((())())";
87
+ static UChar* pattern1
88
+ = (UChar* )"\\g<p>(?@<p>\\(\\g<s>\\)){0}(?@<s>(?:\\g<p>)*|){0}";
89
+
90
+ static UChar* str2 = (UChar* )"x00x00x00";
91
+ static UChar* pattern2 = (UChar* )"(?@x(?@\\d+))+";
92
+
93
+ static UChar* str3 = (UChar* )"0123";
94
+ static UChar* pattern3 = (UChar* )"(?@.)(?@.)(?@.)(?@.)";
95
+
96
+ OnigEncoding use_encs[] = { ONIG_ENCODING_ASCII };
97
+ onig_initialize(use_encs, sizeof(use_encs)/sizeof(use_encs[0]));
98
+
99
+ /* enable capture hostory */
100
+ onig_copy_syntax(&syn, ONIG_SYNTAX_DEFAULT);
101
+ onig_set_syntax_op2(&syn,
102
+ onig_get_syntax_op2(&syn) | ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY);
103
+
104
+ r = ex(str1, pattern1, &syn);
105
+ r = ex(str2, pattern2, &syn);
106
+ r = ex(str3, pattern3, &syn);
107
+
108
+ onig_end();
109
+ return r;
110
+ }
@@ -0,0 +1,75 @@
1
+ /*
2
+ * names.c -- example of group name callback.
3
+ */
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+ #include "oniguruma.h"
7
+
8
+ static int
9
+ name_callback(const UChar* name, const UChar* name_end,
10
+ int ngroup_num, int* group_nums,
11
+ regex_t* reg, void* arg)
12
+ {
13
+ int i, gn, ref;
14
+ char* s;
15
+ OnigRegion *region = (OnigRegion* )arg;
16
+
17
+ for (i = 0; i < ngroup_num; i++) {
18
+ gn = group_nums[i];
19
+ ref = onig_name_to_backref_number(reg, name, name_end, region);
20
+ s = (ref == gn ? "*" : "");
21
+ fprintf(stderr, "%s (%d): ", name, gn);
22
+ fprintf(stderr, "(%d-%d) %s\n", region->beg[gn], region->end[gn], s);
23
+ }
24
+ return 0; /* 0: continue */
25
+ }
26
+
27
+ extern int main(int argc, char* argv[])
28
+ {
29
+ int r;
30
+ unsigned char *start, *range, *end;
31
+ regex_t* reg;
32
+ OnigErrorInfo einfo;
33
+ OnigRegion *region;
34
+
35
+ static UChar* pattern = (UChar* )"(?<foo>a*)(?<bar>b*)(?<foo>c*)";
36
+ static UChar* str = (UChar* )"aaabbbbcc";
37
+
38
+ OnigEncoding use_encs[] = { ONIG_ENCODING_ASCII };
39
+ onig_initialize(use_encs, sizeof(use_encs)/sizeof(use_encs[0]));
40
+
41
+ r = onig_new(&reg, pattern, pattern + strlen((char* )pattern),
42
+ ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, ONIG_SYNTAX_DEFAULT, &einfo);
43
+ if (r != ONIG_NORMAL) {
44
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
45
+ onig_error_code_to_str(s, r, &einfo);
46
+ fprintf(stderr, "ERROR: %s\n", s);
47
+ return -1;
48
+ }
49
+
50
+ fprintf(stderr, "number of names: %d\n", onig_number_of_names(reg));
51
+
52
+ region = onig_region_new();
53
+
54
+ end = str + strlen((char* )str);
55
+ start = str;
56
+ range = end;
57
+ r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE);
58
+ if (r >= 0) {
59
+ fprintf(stderr, "match at %d\n\n", r);
60
+ r = onig_foreach_name(reg, name_callback, (void* )region);
61
+ }
62
+ else if (r == ONIG_MISMATCH) {
63
+ fprintf(stderr, "search fail\n");
64
+ }
65
+ else { /* error */
66
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
67
+ onig_error_code_to_str(s, r);
68
+ return -1;
69
+ }
70
+
71
+ onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
72
+ onig_free(reg);
73
+ onig_end();
74
+ return 0;
75
+ }
@@ -0,0 +1,96 @@
1
+ /*
2
+ * posix.c
3
+ */
4
+ #include <stdio.h>
5
+ #include "onigposix.h"
6
+
7
+ typedef unsigned char UChar;
8
+
9
+ static int x(regex_t* reg, unsigned char* pattern, unsigned char* str)
10
+ {
11
+ int r, i;
12
+ char buf[200];
13
+ regmatch_t pmatch[20];
14
+
15
+ r = regexec(reg, (char* )str, reg->re_nsub + 1, pmatch, 0);
16
+ if (r != 0 && r != REG_NOMATCH) {
17
+ regerror(r, reg, buf, sizeof(buf));
18
+ fprintf(stderr, "ERROR: %s\n", buf);
19
+ return -1;
20
+ }
21
+
22
+ if (r == REG_NOMATCH) {
23
+ fprintf(stderr, "FAIL: /%s/ '%s'\n", pattern, str);
24
+ }
25
+ else {
26
+ fprintf(stderr, "OK: /%s/ '%s'\n", pattern, str);
27
+ for (i = 0; i <= (int )reg->re_nsub; i++) {
28
+ fprintf(stderr, "%d: %d-%d\n", i, pmatch[i].rm_so, pmatch[i].rm_eo);
29
+ }
30
+ }
31
+ return 0;
32
+ }
33
+
34
+ extern int main(int argc, char* argv[])
35
+ {
36
+ int r;
37
+ char buf[200];
38
+ regex_t reg;
39
+ UChar* pattern;
40
+
41
+ reg_set_encoding(REG_POSIX_ENCODING_ASCII);
42
+
43
+ /* default syntax (ONIG_SYNTAX_RUBY) */
44
+ pattern = (UChar* )"^a+b{2,7}[c-f]?$|uuu";
45
+ r = regcomp(&reg, (char* )pattern, REG_EXTENDED);
46
+ if (r) {
47
+ regerror(r, &reg, buf, sizeof(buf));
48
+ fprintf(stderr, "ERROR: %s\n", buf);
49
+ return -1;
50
+ }
51
+ x(&reg, pattern, (UChar* )"aaabbbbd");
52
+
53
+ /* POSIX Basic RE (REG_EXTENDED is not specified.) */
54
+ pattern = (UChar* )"^a+b{2,7}[c-f]?|uuu";
55
+ r = regcomp(&reg, (char* )pattern, 0);
56
+ if (r) {
57
+ regerror(r, &reg, buf, sizeof(buf));
58
+ fprintf(stderr, "ERROR: %s\n", buf);
59
+ return -1;
60
+ }
61
+ x(&reg, pattern, (UChar* )"a+b{2,7}d?|uuu");
62
+
63
+ /* POSIX Basic RE (REG_EXTENDED is not specified.) */
64
+ pattern = (UChar* )"^a*b\\{2,7\\}\\([c-f]\\)$";
65
+ r = regcomp(&reg, (char* )pattern, 0);
66
+ if (r) {
67
+ regerror(r, &reg, buf, sizeof(buf));
68
+ fprintf(stderr, "ERROR: %s\n", buf);
69
+ return -1;
70
+ }
71
+ x(&reg, pattern, (UChar* )"aaaabbbbbbd");
72
+
73
+ /* POSIX Extended RE */
74
+ onig_set_default_syntax(ONIG_SYNTAX_POSIX_EXTENDED);
75
+ pattern = (UChar* )"^a+b{2,7}[c-f]?)$|uuu";
76
+ r = regcomp(&reg, (char* )pattern, REG_EXTENDED);
77
+ if (r) {
78
+ regerror(r, &reg, buf, sizeof(buf));
79
+ fprintf(stderr, "ERROR: %s\n", buf);
80
+ return -1;
81
+ }
82
+ x(&reg, pattern, (UChar* )"aaabbbbd)");
83
+
84
+ pattern = (UChar* )"^b.";
85
+ r = regcomp(&reg, (char* )pattern, REG_EXTENDED | REG_NEWLINE);
86
+ if (r) {
87
+ regerror(r, &reg, buf, sizeof(buf));
88
+ fprintf(stderr, "ERROR: %s\n", buf);
89
+ return -1;
90
+ }
91
+ x(&reg, pattern, (UChar* )"a\nb\n");
92
+
93
+ regfree(&reg);
94
+ onig_end();
95
+ return 0;
96
+ }
@@ -0,0 +1,88 @@
1
+ /*
2
+ * scan.c
3
+ */
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+ #include "oniguruma.h"
7
+
8
+ static int
9
+ scan_callback(int n, int r, OnigRegion* region, void* arg)
10
+ {
11
+ int i;
12
+
13
+ fprintf(stdout, "scan: %d\n", n);
14
+
15
+ fprintf(stdout, "match at %d\n", r);
16
+ for (i = 0; i < region->num_regs; i++) {
17
+ fprintf(stdout, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]);
18
+ }
19
+
20
+ return 0;
21
+ }
22
+
23
+ static int
24
+ scan(regex_t* reg, unsigned char* str, unsigned char* end)
25
+ {
26
+ int r;
27
+ OnigRegion *region;
28
+
29
+ region = onig_region_new();
30
+
31
+ r = onig_scan(reg, str, end, region, ONIG_OPTION_NONE, scan_callback, NULL);
32
+ if (r >= 0) {
33
+ fprintf(stdout, "total: %d match\n", r);
34
+ }
35
+ else { /* error */
36
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
37
+ onig_error_code_to_str((OnigUChar* )s, r);
38
+ fprintf(stderr, "ERROR: %s\n", s);
39
+ return -1;
40
+ }
41
+
42
+ onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
43
+ return 0;
44
+ }
45
+
46
+ static int
47
+ exec(OnigEncoding enc, OnigOptionType options, char* apattern, char* astr)
48
+ {
49
+ int r;
50
+ unsigned char *end;
51
+ regex_t* reg;
52
+ OnigErrorInfo einfo;
53
+ UChar* pattern_end;
54
+ UChar* pattern = (UChar* )apattern;
55
+ UChar* str = (UChar* )astr;
56
+
57
+ onig_initialize(&enc, 1);
58
+
59
+ pattern_end = pattern + onigenc_str_bytelen_null(enc, pattern);
60
+
61
+ r = onig_new(&reg, pattern, pattern_end, options, enc, ONIG_SYNTAX_DEFAULT, &einfo);
62
+ if (r != ONIG_NORMAL) {
63
+ char s[ONIG_MAX_ERROR_MESSAGE_LEN];
64
+ onig_error_code_to_str((OnigUChar* )s, r, &einfo);
65
+ fprintf(stderr, "ERROR: %s\n", s);
66
+ return -1;
67
+ }
68
+
69
+ end = str + onigenc_str_bytelen_null(enc, str);
70
+ r = scan(reg, str, end);
71
+
72
+ onig_free(reg);
73
+ onig_end();
74
+ return 0;
75
+ }
76
+
77
+
78
+ extern int main(int argc, char* argv[])
79
+ {
80
+ exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE,
81
+ "\\Ga+\\s*", "a aa aaa baaa");
82
+
83
+ fprintf(stdout, "\n");
84
+ exec(ONIG_ENCODING_UTF8, ONIG_OPTION_NONE,
85
+ "a+\\s*", "a aa aaa baaa");
86
+
87
+ return 0;
88
+ }