From 5e9d33ad49079877ee9461e0449150a28bf0902d Mon Sep 17 00:00:00 2001 From: duerst Date: Fri, 1 Apr 2016 11:58:47 +0000 Subject: * enc/unicode/case-folding.rb, casefold.h: Data generation to implement swapcase functionality for titlecase characters. Swapcase isn't defined by Unicode, because the purpose/usage of swapcase is unclear anyway. The implementation follows a proposal from Nobu, swaping the case of each component of a titlecase character individually. This means that the titlecase characters have to be decomposed. * enc/unicode.c: Code using the above data. * test/ruby/enc/test_case_mapping.rb: Tests for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- enc/unicode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'enc/unicode.c') diff --git a/enc/unicode.c b/enc/unicode.c index dfe8f07490..e663c6aceb 100644 --- a/enc/unicode.c +++ b/enc/unicode.c @@ -139,7 +139,7 @@ code3_equal(const OnigCodePoint *x, const OnigCodePoint *y) /* macros related to ONIGENC_CASE flags */ /* defined here because not used in other files */ -#define ONIGENC_CASE_SPECIALS (ONIGENC_CASE_TITLECASE|ONIGENC_CASE_UP_SPECIAL|ONIGENC_CASE_DOWN_SPECIAL) +#define ONIGENC_CASE_SPECIALS (ONIGENC_CASE_TITLECASE|ONIGENC_CASE_IS_TITLECASE|ONIGENC_CASE_UP_SPECIAL|ONIGENC_CASE_DOWN_SPECIAL) /* macros for length in CaseMappingSpecials array in enc/unicode/casefold.h */ #define SpecialsLengthOffset 25 /* needs to be higher than the 22 bits used for Unicode codepoints */ @@ -715,6 +715,13 @@ onigenc_unicode_case_map(OnigCaseFoldType* flagP, if (flags&OnigCaseFoldFlags(folded->n)&ONIGENC_CASE_SPECIALS) { /* special */ OnigCodePoint *SpecialsStart = CaseMappingSpecials + OnigSpecialIndexDecode(folded->n); + if (OnigCaseFoldFlags(folded->n)&ONIGENC_CASE_IS_TITLECASE) { /* swapCASE available */ + if ((flags&(ONIGENC_CASE_UPCASE|ONIGENC_CASE_DOWNCASE)) + == (ONIGENC_CASE_UPCASE|ONIGENC_CASE_DOWNCASE)) /* swapCASE needed */ + goto SpecialsCopy; + else /* swapCASE not needed */ + SpecialsStart += SpecialsLengthExtract(*SpecialsStart); + } if (OnigCaseFoldFlags(folded->n)&ONIGENC_CASE_TITLECASE) { /* Titlecase available */ if (flags&ONIGENC_CASE_TITLECASE) /* Titlecase needed, but not yet Titlecase */ goto SpecialsCopy; -- cgit v1.2.3