@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.
- package/binding.gyp +3 -3
- package/configure +8 -6
- package/deps/jq/.travis.yml +184 -35
- package/deps/jq/AUTHORS +31 -30
- package/deps/jq/COPYING +2 -2
- package/deps/jq/KEYS +8 -0
- package/deps/jq/Makefile.am +85 -70
- package/deps/jq/NEWS +5 -4
- package/deps/jq/README.md +18 -9
- package/deps/jq/appveyor.yml +53 -0
- package/deps/jq/compile-ios.sh +5 -5
- package/deps/jq/config/m4/check-math-func.m4 +7 -2
- package/deps/jq/configure.ac +130 -68
- package/deps/jq/docs/Rakefile +14 -135
- package/deps/jq/docs/Rakefile.manual +49 -0
- package/deps/jq/docs/Rakefile.website +76 -0
- package/deps/jq/docs/content/2.download/default.yml +115 -39
- package/deps/jq/docs/content/3.manual/manual.yml +641 -231
- package/deps/jq/docs/content/3.manual/v1.3/manual.yml +130 -130
- package/deps/jq/docs/content/3.manual/v1.4/manual.yml +160 -160
- package/deps/jq/docs/content/3.manual/v1.5/manual.yml +2878 -0
- package/deps/jq/docs/content/3.manual/v1.6/manual.yml +3287 -0
- package/deps/jq/docs/content/index/index.yml +28 -6
- package/deps/jq/docs/public/.htaccess +2 -2
- package/deps/jq/docs/public/css/base.scss +141 -59
- package/deps/jq/docs/public/js/manual-search.js +52 -0
- package/deps/jq/docs/site.yml +1 -10
- package/deps/jq/docs/templates/default.liquid +10 -10
- package/deps/jq/docs/templates/index.liquid +45 -32
- package/deps/jq/docs/templates/manual.liquid +67 -90
- package/deps/jq/docs/templates/shared/_footer.liquid +10 -5
- package/deps/jq/docs/templates/shared/_head.liquid +17 -12
- package/deps/jq/docs/templates/shared/_navbar.liquid +27 -0
- package/deps/jq/jq.1.prebuilt +523 -139
- package/deps/jq/modules/oniguruma/AUTHORS +1 -0
- package/deps/jq/modules/oniguruma/CMakeLists.txt +86 -0
- package/deps/jq/modules/oniguruma/COPYING +28 -0
- package/deps/jq/modules/oniguruma/ChangeLog +0 -0
- package/deps/jq/modules/oniguruma/HISTORY +2138 -0
- package/deps/jq/modules/oniguruma/Makefile.am +33 -0
- package/deps/jq/modules/oniguruma/NEWS +0 -0
- package/deps/jq/modules/oniguruma/README +189 -0
- package/deps/jq/modules/oniguruma/README.ja +195 -0
- package/deps/jq/modules/oniguruma/README.md +203 -0
- package/deps/jq/modules/oniguruma/cmake/dist.cmake +321 -0
- package/deps/jq/modules/oniguruma/compile +348 -0
- package/deps/jq/modules/oniguruma/config.guess +1754 -0
- package/deps/jq/modules/oniguruma/config.sub +1890 -0
- package/deps/jq/modules/oniguruma/configure.ac +87 -0
- package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +31 -0
- package/deps/jq/modules/oniguruma/depcomp +791 -0
- package/deps/jq/modules/oniguruma/dist.info +10 -0
- package/deps/jq/modules/oniguruma/doc/API +660 -0
- package/deps/jq/modules/oniguruma/doc/API.ja +667 -0
- package/deps/jq/modules/oniguruma/doc/FAQ +12 -0
- package/deps/jq/modules/oniguruma/doc/FAQ.ja +22 -0
- package/deps/jq/modules/oniguruma/doc/RE +436 -0
- package/deps/jq/modules/oniguruma/doc/RE.ja +448 -0
- package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +698 -0
- package/deps/jq/modules/oniguruma/index.html +181 -0
- package/deps/jq/modules/oniguruma/index_ja.html +184 -0
- package/deps/jq/modules/oniguruma/install-sh +541 -0
- package/deps/jq/modules/oniguruma/m4/.whatever +0 -0
- package/deps/jq/modules/oniguruma/make_win32.bat +3 -0
- package/deps/jq/modules/oniguruma/make_win64.bat +3 -0
- package/deps/jq/modules/oniguruma/missing +215 -0
- package/deps/jq/modules/oniguruma/onig-config.in +78 -0
- package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +13 -0
- package/deps/jq/modules/oniguruma/oniguruma.pc.in +14 -0
- package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +28 -0
- package/deps/jq/modules/oniguruma/sample/Makefile.am +34 -0
- package/deps/jq/modules/oniguruma/sample/bug_fix.c +131 -0
- package/deps/jq/modules/oniguruma/sample/crnl.c +127 -0
- package/deps/jq/modules/oniguruma/sample/encode.c +308 -0
- package/deps/jq/modules/oniguruma/sample/listcap.c +110 -0
- package/deps/jq/modules/oniguruma/sample/names.c +75 -0
- package/deps/jq/modules/oniguruma/sample/posix.c +96 -0
- package/deps/jq/modules/oniguruma/sample/scan.c +88 -0
- package/deps/jq/modules/oniguruma/sample/simple.c +59 -0
- package/deps/jq/modules/oniguruma/sample/sql.c +76 -0
- package/deps/jq/modules/oniguruma/sample/syntax.c +76 -0
- package/deps/jq/modules/oniguruma/sample/user_property.c +87 -0
- package/deps/jq/modules/oniguruma/src/Makefile.am +58 -0
- package/deps/jq/modules/oniguruma/src/Makefile.windows +183 -0
- package/deps/jq/modules/oniguruma/src/ascii.c +61 -0
- package/deps/jq/modules/oniguruma/src/big5.c +190 -0
- package/deps/jq/modules/oniguruma/src/config.h.cmake.in +71 -0
- package/deps/jq/modules/oniguruma/src/config.h.win32 +84 -0
- package/deps/jq/modules/oniguruma/src/config.h.win64 +84 -0
- package/deps/jq/modules/oniguruma/src/cp1251.c +203 -0
- package/deps/jq/modules/oniguruma/src/euc_jp.c +310 -0
- package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +158 -0
- package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +27 -0
- package/deps/jq/modules/oniguruma/src/euc_kr.c +188 -0
- package/deps/jq/modules/oniguruma/src/euc_tw.c +171 -0
- package/deps/jq/modules/oniguruma/src/gb18030.c +538 -0
- package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +67 -0
- package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +55 -0
- package/deps/jq/modules/oniguruma/src/iso8859_1.c +275 -0
- package/deps/jq/modules/oniguruma/src/iso8859_10.c +242 -0
- package/deps/jq/modules/oniguruma/src/iso8859_11.c +99 -0
- package/deps/jq/modules/oniguruma/src/iso8859_13.c +231 -0
- package/deps/jq/modules/oniguruma/src/iso8859_14.c +244 -0
- package/deps/jq/modules/oniguruma/src/iso8859_15.c +238 -0
- package/deps/jq/modules/oniguruma/src/iso8859_16.c +240 -0
- package/deps/jq/modules/oniguruma/src/iso8859_2.c +238 -0
- package/deps/jq/modules/oniguruma/src/iso8859_3.c +238 -0
- package/deps/jq/modules/oniguruma/src/iso8859_4.c +240 -0
- package/deps/jq/modules/oniguruma/src/iso8859_5.c +229 -0
- package/deps/jq/modules/oniguruma/src/iso8859_6.c +99 -0
- package/deps/jq/modules/oniguruma/src/iso8859_7.c +225 -0
- package/deps/jq/modules/oniguruma/src/iso8859_8.c +99 -0
- package/deps/jq/modules/oniguruma/src/iso8859_9.c +231 -0
- package/deps/jq/modules/oniguruma/src/koi8.c +253 -0
- package/deps/jq/modules/oniguruma/src/koi8_r.c +215 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +22 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +306 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +18 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +545 -0
- package/deps/jq/modules/oniguruma/src/mktable.c +1184 -0
- package/deps/jq/modules/oniguruma/src/onig_init.c +45 -0
- package/deps/jq/modules/oniguruma/src/oniggnu.h +85 -0
- package/deps/jq/modules/oniguruma/src/onigposix.h +169 -0
- package/deps/jq/modules/oniguruma/src/oniguruma.h +841 -0
- package/deps/jq/modules/oniguruma/src/regcomp.c +6300 -0
- package/deps/jq/modules/oniguruma/src/regenc.c +917 -0
- package/deps/jq/modules/oniguruma/src/regenc.h +243 -0
- package/deps/jq/modules/oniguruma/src/regerror.c +393 -0
- package/deps/jq/modules/oniguruma/src/regexec.c +3856 -0
- package/deps/jq/modules/oniguruma/src/regext.c +202 -0
- package/deps/jq/modules/oniguruma/src/reggnu.c +147 -0
- package/deps/jq/modules/oniguruma/src/regint.h +779 -0
- package/deps/jq/modules/oniguruma/src/regparse.c +5403 -0
- package/deps/jq/modules/oniguruma/src/regparse.h +351 -0
- package/deps/jq/modules/oniguruma/src/regposerr.c +105 -0
- package/deps/jq/modules/oniguruma/src/regposix.c +306 -0
- package/deps/jq/modules/oniguruma/src/regsyntax.c +315 -0
- package/deps/jq/modules/oniguruma/src/regtrav.c +76 -0
- package/deps/jq/modules/oniguruma/src/regversion.c +57 -0
- package/deps/jq/modules/oniguruma/src/sjis.c +341 -0
- package/deps/jq/modules/oniguruma/src/sjis_prop.c +158 -0
- package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +27 -0
- package/deps/jq/modules/oniguruma/src/st.c +589 -0
- package/deps/jq/modules/oniguruma/src/st.h +68 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +2250 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +203 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +113 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +1225 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +24742 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +4846 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +2571 -0
- package/deps/jq/modules/oniguruma/src/unicode.c +664 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +2548 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +203 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +113 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1366 -0
- package/deps/jq/modules/oniguruma/src/unicode_property_data.c +25306 -0
- package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +4940 -0
- package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +2854 -0
- package/deps/jq/modules/oniguruma/src/utf16_be.c +235 -0
- package/deps/jq/modules/oniguruma/src/utf16_le.c +245 -0
- package/deps/jq/modules/oniguruma/src/utf32_be.c +194 -0
- package/deps/jq/modules/oniguruma/src/utf32_le.c +194 -0
- package/deps/jq/modules/oniguruma/src/utf8.c +335 -0
- package/deps/jq/modules/oniguruma/test/Makefile.am +28 -0
- package/deps/jq/modules/oniguruma/test/testc.c +874 -0
- package/deps/jq/modules/oniguruma/test/testu.c +916 -0
- package/deps/jq/modules/oniguruma/test-driver +153 -0
- package/deps/jq/modules/oniguruma/windows/testc.c +869 -0
- package/deps/jq/scripts/crosscompile +2 -1
- package/deps/jq/scripts/gen_utf8_tables.py +2 -3
- package/deps/jq/scripts/update-website +29 -0
- package/deps/jq/scripts/version +7 -2
- package/deps/jq/sig/jq-release.key +41 -0
- package/deps/jq/sig/v1.3/jq-linux-x86.asc +17 -0
- package/deps/jq/sig/v1.3/jq-linux-x86_64.asc +17 -0
- package/deps/jq/sig/v1.3/jq-osx-x86.asc +17 -0
- package/deps/jq/sig/v1.3/jq-osx-x86_64.asc +17 -0
- package/deps/jq/sig/v1.3/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.3/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.3/sha256sum.txt +6 -0
- package/deps/jq/sig/v1.4/jq-linux-x86.asc +17 -0
- package/deps/jq/sig/v1.4/jq-linux-x86_64.asc +17 -0
- package/deps/jq/sig/v1.4/jq-osx-x86.asc +17 -0
- package/deps/jq/sig/v1.4/jq-osx-x86_64.asc +17 -0
- package/deps/jq/sig/v1.4/jq-solaris11-32.asc +17 -0
- package/deps/jq/sig/v1.4/jq-solaris11-64.asc +17 -0
- package/deps/jq/sig/v1.4/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.4/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.4/sha256sum.txt +8 -0
- package/deps/jq/sig/v1.5/jq-linux32-no-oniguruma.asc +17 -0
- package/deps/jq/sig/v1.5/jq-linux32.asc +17 -0
- package/deps/jq/sig/v1.5/jq-linux64.asc +17 -0
- package/deps/jq/sig/v1.5/jq-osx-amd64.asc +17 -0
- package/deps/jq/sig/v1.5/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.5/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.5/sha256sum.txt +5 -0
- package/deps/jq/sig/v1.5rc1/jq-linux-x86_64-static.asc +17 -0
- package/deps/jq/sig/v1.5rc1/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc1/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc1/sha256sum.txt +3 -0
- package/deps/jq/sig/v1.5rc2/jq-linux-x86.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-linux-x86_64.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-osx-x86_64.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc2/sha256sum.txt +5 -0
- package/deps/jq/sig/v1.6/jq-linux32.asc +16 -0
- package/deps/jq/sig/v1.6/jq-linux64.asc +16 -0
- package/deps/jq/sig/v1.6/jq-osx-amd64.asc +16 -0
- package/deps/jq/sig/v1.6/jq-win32.exe.asc +16 -0
- package/deps/jq/sig/v1.6/jq-win64.exe.asc +16 -0
- package/deps/jq/sig/v1.6/sha256sum.txt +5 -0
- package/deps/jq/{builtin.c → src/builtin.c} +449 -344
- package/deps/jq/{builtin.h → src/builtin.h} +0 -0
- package/deps/jq/src/builtin.jq +311 -0
- package/deps/jq/{bytecode.c → src/bytecode.c} +0 -0
- package/deps/jq/{bytecode.h → src/bytecode.h} +0 -0
- package/deps/jq/{compile.c → src/compile.c} +213 -37
- package/deps/jq/{compile.h → src/compile.h} +7 -2
- package/deps/jq/{exec_stack.h → src/exec_stack.h} +0 -0
- package/deps/jq/{execute.c → src/execute.c} +127 -24
- package/deps/jq/{inject_errors.c → src/inject_errors.c} +0 -0
- package/deps/jq/{jq.h → src/jq.h} +13 -2
- package/deps/jq/{jq_parser.h → src/jq_parser.h} +0 -0
- package/deps/jq/{jq_test.c → src/jq_test.c} +1 -1
- package/deps/jq/{jv.c → src/jv.c} +24 -5
- package/deps/jq/{jv.h → src/jv.h} +46 -11
- package/deps/jq/{jv_alloc.c → src/jv_alloc.c} +0 -0
- package/deps/jq/{jv_alloc.h → src/jv_alloc.h} +0 -0
- package/deps/jq/{jv_aux.c → src/jv_aux.c} +38 -14
- package/deps/jq/{jv_dtoa.c → src/jv_dtoa.c} +4 -5
- package/deps/jq/{jv_dtoa.h → src/jv_dtoa.h} +0 -0
- package/deps/jq/src/jv_file.c +81 -0
- package/deps/jq/{jv_parse.c → src/jv_parse.c} +8 -2
- package/deps/jq/{jv_print.c → src/jv_print.c} +80 -27
- package/deps/jq/{jv_unicode.c → src/jv_unicode.c} +28 -4
- package/deps/jq/{jv_unicode.h → src/jv_unicode.h} +1 -0
- package/deps/jq/{jv_utf8_tables.h → src/jv_utf8_tables.h} +0 -0
- package/deps/jq/{lexer.c → src/lexer.c} +317 -292
- package/deps/jq/{lexer.h → src/lexer.h} +16 -12
- package/deps/jq/{lexer.l → src/lexer.l} +5 -4
- package/deps/jq/src/libm.h +291 -0
- package/deps/jq/{linker.c → src/linker.c} +5 -3
- package/deps/jq/{linker.h → src/linker.h} +0 -0
- package/deps/jq/{locfile.c → src/locfile.c} +1 -1
- package/deps/jq/{locfile.h → src/locfile.h} +0 -0
- package/deps/jq/{main.c → src/main.c} +202 -100
- package/deps/jq/{opcode_list.h → src/opcode_list.h} +4 -0
- package/deps/jq/{parser.c → src/parser.c} +1149 -1069
- package/deps/jq/{parser.h → src/parser.h} +28 -24
- package/deps/jq/{parser.y → src/parser.y} +108 -52
- package/deps/jq/{util.c → src/util.c} +12 -9
- package/deps/jq/{util.h → src/util.h} +0 -0
- package/deps/jq/tests/base64.test +35 -0
- package/deps/jq/tests/base64test +5 -0
- package/deps/jq/tests/jq-f-test.sh +4 -0
- package/deps/jq/tests/jq.test +305 -21
- package/deps/jq/tests/jqtest +1 -1
- package/deps/jq/tests/mantest +1 -1
- package/deps/jq/tests/onig.test +13 -0
- package/deps/jq/tests/onigtest +1 -1
- package/deps/jq/tests/optional.test +20 -0
- package/deps/jq/tests/optionaltest +5 -0
- package/deps/jq/tests/setup +7 -1
- package/deps/jq/tests/shtest +133 -29
- package/deps/jq/tests/utf8-truncate.jq +3 -0
- package/deps/jq/tests/utf8test +10 -0
- package/lib/index.js +7 -1
- package/package.json +3 -3
- package/test/santiy.test.js +24 -0
- package/deps/jq/docs/default_manpage.md +0 -22
- package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +0 -1058
- package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +0 -9
- package/deps/jq/docs/public/bootstrap/css/bootstrap.css +0 -5224
- package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +0 -9
- package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
- package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
- package/deps/jq/docs/public/bootstrap/js/bootstrap.js +0 -2027
- package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +0 -6
- package/deps/jq/docs/templates/shared/_header.liquid +0 -26
- package/deps/jq/jq.1.default +0 -39
- package/deps/jq/jv_file.c +0 -49
- package/deps/jq/libm.h +0 -160
- package/deps/jq/setup.sh +0 -33
- 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(®, 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(®, 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(®, 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(®, 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(®, (char* )pattern, REG_EXTENDED);
|
|
46
|
+
if (r) {
|
|
47
|
+
regerror(r, ®, buf, sizeof(buf));
|
|
48
|
+
fprintf(stderr, "ERROR: %s\n", buf);
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
x(®, 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(®, (char* )pattern, 0);
|
|
56
|
+
if (r) {
|
|
57
|
+
regerror(r, ®, buf, sizeof(buf));
|
|
58
|
+
fprintf(stderr, "ERROR: %s\n", buf);
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
x(®, 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(®, (char* )pattern, 0);
|
|
66
|
+
if (r) {
|
|
67
|
+
regerror(r, ®, buf, sizeof(buf));
|
|
68
|
+
fprintf(stderr, "ERROR: %s\n", buf);
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
x(®, 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(®, (char* )pattern, REG_EXTENDED);
|
|
77
|
+
if (r) {
|
|
78
|
+
regerror(r, ®, buf, sizeof(buf));
|
|
79
|
+
fprintf(stderr, "ERROR: %s\n", buf);
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
x(®, pattern, (UChar* )"aaabbbbd)");
|
|
83
|
+
|
|
84
|
+
pattern = (UChar* )"^b.";
|
|
85
|
+
r = regcomp(®, (char* )pattern, REG_EXTENDED | REG_NEWLINE);
|
|
86
|
+
if (r) {
|
|
87
|
+
regerror(r, ®, buf, sizeof(buf));
|
|
88
|
+
fprintf(stderr, "ERROR: %s\n", buf);
|
|
89
|
+
return -1;
|
|
90
|
+
}
|
|
91
|
+
x(®, pattern, (UChar* )"a\nb\n");
|
|
92
|
+
|
|
93
|
+
regfree(®);
|
|
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(®, 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
|
+
}
|