summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-07 00:26:41 +0000
committerduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-07 00:26:41 +0000
commitc8c9eff25c8d6205ddd34a2bc7969d7967354aec (patch)
treed3a5582c362fa10cf6077b92feaad309eb1292e7
parentc25fa0fa9e463d33854d1b0c421614ca34890e98 (diff)
* regenc.c (onigenc_not_support_case_map): Rewrite to work correctly
in ASCII range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--regenc.c29
2 files changed, 31 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a269ec3ad..fa0626a73f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jun 7 09:26:37 2016 Martin Duerst <duerst@it.aoyama.ac.jp>
+
+ * regenc.c (onigenc_not_support_case_map): Rewrite to work correctly
+ in ASCII range.
+
Mon Jun 6 23:00:00 2016 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* appveyor.yml: Update libressl version to 2.3.5.
diff --git a/regenc.c b/regenc.c
index 4c466aedbb..eb159af79b 100644
--- a/regenc.c
+++ b/regenc.c
@@ -578,10 +578,33 @@ onigenc_not_support_get_ctype_code_range(OnigCtype ctype ARG_UNUSED,
#ifdef ONIG_CASE_MAPPING
extern int
-onigenc_not_support_case_map (OnigCaseFoldType* flagP, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to, OnigUChar* to_end, const struct OnigEncodingTypeST* enc)
+onigenc_not_support_case_map (OnigCaseFoldType* flagP, const OnigUChar** pp, const OnigUChar* end,
+ OnigUChar* to, OnigUChar* to_end, const struct OnigEncodingTypeST* enc)
{
- fprintf(stderr, "Unimplemented case mapping functionality: onigenc_not_support_case_map\n");
- return ONIG_NO_SUPPORT_CONFIG;
+ OnigCodePoint code;
+ OnigUChar *to_start = to;
+ OnigCaseFoldType flags = *flagP;
+ int codepoint_length;
+
+ to_end -= 4; /* longest possible length of a single character */
+
+ while (*pp<end && to<=to_end) {
+ codepoint_length = ONIGENC_PRECISE_MBC_ENC_LEN(enc, *pp, end);
+ if (codepoint_length < 0)
+ return codepoint_length; /* encoding invalid */
+ code = ONIGENC_MBC_TO_CODE(enc, *pp, end);
+ *pp += codepoint_length;
+
+ if (code>='a' && code<='z' && (flags&ONIGENC_CASE_UPCASE))
+ flags |= ONIGENC_CASE_MODIFIED, code += 'A'-'a';
+ else if (code>='A' && code<='Z' && (flags&(ONIGENC_CASE_DOWNCASE|ONIGENC_CASE_FOLD)))
+ flags |= ONIGENC_CASE_MODIFIED, code += 'a'-'A';
+ to += ONIGENC_CODE_TO_MBC(enc, code, to);
+ if (flags & ONIGENC_CASE_TITLECASE) /* switch from titlecase to lowercase for capitalize */
+ flags ^= (ONIGENC_CASE_UPCASE|ONIGENC_CASE_DOWNCASE|ONIGENC_CASE_TITLECASE);
+ }
+ *flagP = flags;
+ return (int)(to-to_start);
}
#endif /* ONIG_CASE_MAPPING */