summaryrefslogtreecommitdiff
path: root/sample/encode.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2019-08-07 09:32:48 +0200
committerJörg Frings-Fürst <debian@jff.email>2019-08-07 09:32:48 +0200
commit40f3d0030e6e98bcb02d6523e5ee48497dec49a6 (patch)
treea992f9a6acd3edc2c7bb6b1aba2e52084918c9ab /sample/encode.c
parente25c754918ae26e8b9e68a47bc1af36248e91800 (diff)
New upstream version 6.9.3upstream/6.9.3
Diffstat (limited to 'sample/encode.c')
-rw-r--r--sample/encode.c142
1 files changed, 24 insertions, 118 deletions
diff --git a/sample/encode.c b/sample/encode.c
index 8a03ab8..c5d4771 100644
--- a/sample/encode.c
+++ b/sample/encode.c
@@ -34,6 +34,7 @@ search(regex_t* reg, unsigned char* str, unsigned char* end)
onig_error_code_to_str((UChar* )s, r);
fprintf(stderr, "ERROR: %s\n", s);
fprintf(stderr, " (%s)\n", ONIGENC_NAME(onig_get_encoding(reg)));
+ onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
return -1;
}
@@ -72,55 +73,6 @@ exec(OnigEncoding enc, OnigOptionType options,
return 0;
}
-static OnigCaseFoldType CF = ONIGENC_CASE_FOLD_MIN;
-
-#if 0
-static void
-set_case_fold(OnigCaseFoldType cf)
-{
- CF = cf;
-}
-#endif
-
-static int
-exec_deluxe(OnigEncoding pattern_enc, OnigEncoding str_enc,
- OnigOptionType options, char* apattern, char* astr)
-{
- int r;
- unsigned char *end;
- regex_t* reg;
- OnigCompileInfo ci;
- OnigErrorInfo einfo;
- UChar* pattern = (UChar* )apattern;
- UChar* str = (UChar* )astr;
-
- onig_initialize(&str_enc, 1);
-
- ci.num_of_elements = 5;
- ci.pattern_enc = pattern_enc;
- ci.target_enc = str_enc;
- ci.syntax = ONIG_SYNTAX_DEFAULT;
- ci.option = options;
- ci.case_fold_flag = CF;
-
- r = onig_new_deluxe(&reg, pattern,
- pattern + onigenc_str_bytelen_null(pattern_enc, pattern),
- &ci, &einfo);
- if (r != ONIG_NORMAL) {
- char s[ONIG_MAX_ERROR_MESSAGE_LEN];
- onig_error_code_to_str((UChar* )s, r, &einfo);
- fprintf(stderr, "ERROR: %s\n", s);
- return -1;
- }
-
- end = str + onigenc_str_bytelen_null(str_enc, str);
- r = search(reg, str, end);
-
- onig_free(reg);
- onig_end();
- return 0;
-}
-
extern int main(int argc, char* argv[])
{
int r;
@@ -196,39 +148,6 @@ extern int main(int argc, char* argv[])
r = exec(ONIG_ENCODING_ISO_8859_1, ONIG_OPTION_IGNORECASE,
"is", "iss");
- r = exec_deluxe(ONIG_ENCODING_ASCII, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_NONE, "a+",
- "\000b\000a\000a\000a\000c\000c\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_ASCII, ONIG_ENCODING_UTF16_LE,
- ONIG_OPTION_NONE, "a+",
- "b\000a\000a\000a\000a\000c\000\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_LE,
- ONIG_OPTION_NONE,
- "\000b\000a\000a\000a\000c\000c\000\000",
- "x\000b\000a\000a\000a\000c\000c\000\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\337", "\000S\000S\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "SS", "\000\337\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_LE,
- ONIG_OPTION_IGNORECASE,
- "\337", "S\000S\000\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF32_BE,
- ONIG_OPTION_IGNORECASE,
- "SS", "\000\000\000\337\000\000\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF32_LE,
- ONIG_OPTION_IGNORECASE,
- "\337", "S\000\000\000S\000\000\000\000\000\000\000");
-
r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_NONE,
"\000[\000[\000:\000a\000l\000n\000u\000m\000:\000]\000]\000+\000\000",
"\000#\002\120\000a\000Z\012\077\012\076\012\075\000\000");
@@ -242,44 +161,34 @@ extern int main(int argc, char* argv[])
r = exec(ONIG_ENCODING_GB18030, ONIG_OPTION_IGNORECASE,
"(Aa\\d)+", "BaA5Aa0234");
- r = exec_deluxe(ONIG_ENCODING_ISO_8859_1, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_NONE,
- "^\\P{Hiragana}\\p{^Hiragana}(\\p{Hiragana}+)$",
- "\060\100\060\240\060\101\060\102\060\226\060\237\000\000");
-
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\000[\000\337\000]\000\000", "\000S\000S\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\000[\000\337\000]\000\000", "\000S\000S\000\000");
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\000[\000\337\000]\000\000", "\000s\000S\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\000[\000\337\000]\000\000", "\000s\000S\000\000");
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\000^\000[\000\001\000-\377\375\000]\000$\000\000",
- "\000s\000S\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\000^\000[\000\001\000-\377\375\000]\000$\000\000",
+ "\000s\000S\000\000");
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\000S\000S\000\000",
- "\000S\000T\000\337\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\000S\000S\000\000",
+ "\000S\000T\000\337\000\000");
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\000S\000T\000S\000S\000\000",
- "\000S\000t\000s\000S\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\000S\000T\000S\000S\000\000",
+ "\000S\000t\000s\000S\000\000");
{
UChar pat[] = { 0x1f, 0xfc, 0x00, 0x00 };
UChar str1[] = { 0x21, 0x26, 0x1f, 0xbe, 0x00, 0x00 };
UChar str2[] = { 0x1f, 0xf3, 0x00, 0x00 };
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE, (char* )pat, (char* )str1);
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ (char* )pat, (char* )str1);
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE, (char* )pat, (char* )str2);
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ (char* )pat, (char* )str2);
}
#if 0
@@ -287,17 +196,14 @@ extern int main(int argc, char* argv[])
set_case_fold(ONIGENC_CASE_FOLD_TURKISH_AZERI);
- r = exec_deluxe(ONIG_ENCODING_UTF8, ONIG_ENCODING_UTF8,
- ONIG_OPTION_IGNORECASE,
- "Ii", "\304\261\304\260");
+ r = exec(ONIG_ENCODING_UTF8, ONIG_ENCODING_UTF8, ONIG_OPTION_IGNORECASE,
+ "Ii", "\304\261\304\260");
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\000I\000i\000\000", "\001\061\001\060\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\000I\000i\000\000", "\001\061\001\060\000\000");
- r = exec_deluxe(ONIG_ENCODING_UTF16_BE, ONIG_ENCODING_UTF16_BE,
- ONIG_OPTION_IGNORECASE,
- "\001\061\001\060\000\000", "\000I\000i\000\000");
+ r = exec(ONIG_ENCODING_UTF16_BE, ONIG_OPTION_IGNORECASE,
+ "\001\061\001\060\000\000", "\000I\000i\000\000");
set_case_fold(ONIGENC_CASE_FOLD_MIN);
#endif