regenc.c - Oniguruma (regular expression library)\r
**********************************************************************/\r
/*-\r
- * Copyright (c) 2002-2018 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>\r
+ * Copyright (c) 2002-2019 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>\r
* All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
return 0;\r
}\r
\r
+static int OnigEncInited;\r
+\r
+extern int\r
+onigenc_init(void)\r
+{\r
+ if (OnigEncInited != 0) return 0;\r
+\r
+ OnigEncInited = 1;\r
+ return 0;\r
+}\r
+\r
extern int\r
onigenc_end(void)\r
{\r
InitedList[i].enc = 0;\r
InitedList[i].inited = 0;\r
}\r
-\r
InitedListNum = 0;\r
- return ONIG_NORMAL;\r
-}\r
\r
-extern int\r
-onigenc_init(void)\r
-{\r
- return 0;\r
+ OnigEncInited = 0;\r
+ return ONIG_NORMAL;\r
}\r
\r
extern int\r
\r
extern UChar*\r
onigenc_get_right_adjust_char_head_with_prev(OnigEncoding enc,\r
- const UChar* start, const UChar* s, const UChar** prev)\r
+ const UChar* start, const UChar* s, const UChar** prev)\r
{\r
UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);\r
\r
{\r
int n = 0;\r
UChar* q = (UChar* )p;\r
- \r
+\r
while (q < end) {\r
q += ONIGENC_MBC_ENC_LEN(enc, q);\r
n++;\r
{\r
int n = 0;\r
UChar* p = (UChar* )s;\r
- \r
+\r
while (1) {\r
if (*p == '\0') {\r
UChar* q;\r
\r
extern int\r
onigenc_ascii_apply_all_case_fold(OnigCaseFoldType flag ARG_UNUSED,\r
- OnigApplyAllCaseFoldFunc f, void* arg)\r
+ OnigApplyAllCaseFoldFunc f, void* arg)\r
{\r
OnigCodePoint code;\r
int i, r;\r
\r
extern int\r
onigenc_ascii_get_case_fold_codes_by_str(OnigCaseFoldType flag ARG_UNUSED,\r
- const OnigUChar* p, const OnigUChar* end ARG_UNUSED,\r
- OnigCaseFoldCodeItem items[])\r
+ const OnigUChar* p, const OnigUChar* end ARG_UNUSED,\r
+ OnigCaseFoldCodeItem items[])\r
{\r
if (0x41 <= *p && *p <= 0x5a) {\r
items[0].byte_len = 1;\r
\r
static int\r
ss_apply_all_case_fold(OnigCaseFoldType flag ARG_UNUSED,\r
- OnigApplyAllCaseFoldFunc f, void* arg)\r
+ OnigApplyAllCaseFoldFunc f, void* arg)\r
{\r
static OnigCodePoint ss[] = { 0x73, 0x73 };\r
\r
items[0].code_len = 1;\r
items[0].code[0] = (OnigCodePoint )(*p + 0x20);\r
if (*p == 0x53 && ess_tsett_flag != 0 && end > p + 1\r
- && (*(p+1) == 0x53 || *(p+1) == 0x73)) {\r
+ && (*(p+1) == 0x53 || *(p+1) == 0x73)) {\r
/* SS */\r
items[1].byte_len = 2;\r
items[1].code_len = 1;\r
items[0].code_len = 1;\r
items[0].code[0] = (OnigCodePoint )(*p - 0x20);\r
if (*p == 0x73 && ess_tsett_flag != 0 && end > p + 1\r
- && (*(p+1) == 0x73 || *(p+1) == 0x53)) {\r
+ && (*(p+1) == 0x73 || *(p+1) == 0x53)) {\r
/* ss */\r
items[1].byte_len = 2;\r
items[1].code_len = 1;\r
\r
for (i = 0; i < map_size; i++) {\r
if (*p == map[i].from) {\r
- items[0].byte_len = 1;\r
- items[0].code_len = 1;\r
- items[0].code[0] = map[i].to;\r
- return 1;\r
+ items[0].byte_len = 1;\r
+ items[0].code_len = 1;\r
+ items[0].code[0] = map[i].to;\r
+ return 1;\r
}\r
else if (*p == map[i].to) {\r
- items[0].byte_len = 1;\r
- items[0].code_len = 1;\r
- items[0].code[0] = map[i].from;\r
- return 1;\r
+ items[0].byte_len = 1;\r
+ items[0].code_len = 1;\r
+ items[0].code[0] = map[i].from;\r
+ return 1;\r
}\r
}\r
}\r
\r
extern int\r
onigenc_not_support_get_ctype_code_range(OnigCtype ctype ARG_UNUSED,\r
- OnigCodePoint* sb_out ARG_UNUSED,\r
- const OnigCodePoint* ranges[] ARG_UNUSED)\r
+ OnigCodePoint* sb_out ARG_UNUSED,\r
+ const OnigCodePoint* ranges[] ARG_UNUSED)\r
{\r
return ONIG_NO_SUPPORT_CONFIG;\r
}\r
/* for single byte encodings */\r
extern int\r
onigenc_ascii_mbc_case_fold(OnigCaseFoldType flag ARG_UNUSED, const UChar** p,\r
- const UChar*end ARG_UNUSED, UChar* lower)\r
+ const UChar*end ARG_UNUSED, UChar* lower)\r
{\r
*lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(**p);\r
\r
#if 0\r
extern int\r
onigenc_ascii_is_mbc_ambiguous(OnigCaseFoldType flag,\r
- const UChar** pp, const UChar* end)\r
+ const UChar** pp, const UChar* end)\r
{\r
const UChar* p = *pp;\r
\r
\r
extern UChar*\r
onigenc_single_byte_left_adjust_char_head(const UChar* start ARG_UNUSED,\r
- const UChar* s)\r
+ const UChar* s)\r
{\r
return (UChar* )s;\r
}\r
\r
extern int\r
onigenc_always_true_is_allowed_reverse_match(const UChar* s ARG_UNUSED,\r
- const UChar* end ARG_UNUSED)\r
+ const UChar* end ARG_UNUSED)\r
{\r
return TRUE;\r
}\r
\r
extern int\r
onigenc_always_false_is_allowed_reverse_match(const UChar* s ARG_UNUSED,\r
- const UChar* end ARG_UNUSED)\r
+ const UChar* end ARG_UNUSED)\r
{\r
return FALSE;\r
}\r
\r
extern int\r
onigenc_always_true_is_valid_mbc_string(const UChar* s ARG_UNUSED,\r
- const UChar* end ARG_UNUSED)\r
+ const UChar* end ARG_UNUSED)\r
{\r
return TRUE;\r
}\r
\r
extern int\r
onigenc_length_check_is_valid_mbc_string(OnigEncoding enc,\r
- const UChar* p, const UChar* end)\r
+ const UChar* p, const UChar* end)\r
{\r
while (p < end) {\r
p += enclen(enc, p);\r
extern int\r
onigenc_mbn_mbc_case_fold(OnigEncoding enc, OnigCaseFoldType flag ARG_UNUSED,\r
const UChar** pp, const UChar* end ARG_UNUSED,\r
- UChar* lower)\r
+ UChar* lower)\r
{\r
int len;\r
const UChar *p = *pp;\r
extern int\r
onigenc_mb2_code_to_mbclen(OnigCodePoint code)\r
{\r
+ if ((code & (~0xffff)) != 0) return ONIGERR_INVALID_CODE_POINT_VALUE;\r
+\r
if ((code & 0xff00) != 0) return 2;\r
else return 1;\r
}\r
\r
extern int\r
onigenc_mb2_is_code_ctype(OnigEncoding enc, OnigCodePoint code,\r
- unsigned int ctype)\r
+ unsigned int ctype)\r
{\r
if (code < 128)\r
return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);\r
\r
extern int\r
onigenc_mb4_is_code_ctype(OnigEncoding enc, OnigCodePoint code,\r
- unsigned int ctype)\r
+ unsigned int ctype)\r
{\r
if (code < 128)\r
return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);\r