12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739 |
- // © 2016 and later: Unicode, Inc. and others.
- // License & terms of use: http://www.unicode.org/copyright.html
- /*
- *******************************************************************************
- *
- * Copyright (C) 2004-2014, International Business Machines
- * Corporation and others. All Rights Reserved.
- *
- *******************************************************************************
- * file name: ucase.cpp
- * encoding: UTF-8
- * tab size: 8 (not used)
- * indentation:4
- *
- * created on: 2004aug30
- * created by: Markus W. Scherer
- *
- * Low-level Unicode character/string case mapping code.
- * Much code moved here (and modified) from uchar.c.
- */
- #include "unicode/utypes.h"
- #include "unicode/unistr.h"
- #include "unicode/uset.h"
- #include "unicode/utf16.h"
- #include "cmemory.h"
- #include "uassert.h"
- #include "ucase.h"
- #include "umutex.h"
- #include "utrie2.h"
- /* ucase_props_data.h is machine-generated by genprops/casepropsbuilder.cpp */
- #define INCLUDED_FROM_UCASE_CPP
- #include "ucase_props_data.h"
- /* set of property starts for UnicodeSet ------------------------------------ */
- static UBool U_CALLCONV
- _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 /*end*/, uint32_t /*value*/) {
- /* add the start code point to the USet */
- const USetAdder *sa=(const USetAdder *)context;
- sa->add(sa->set, start);
- return true;
- }
- U_CFUNC void U_EXPORT2
- ucase_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
- if(U_FAILURE(*pErrorCode)) {
- return;
- }
- /* add the start code point of each same-value range of the trie */
- utrie2_enum(&ucase_props_singleton.trie, nullptr, _enumPropertyStartsRange, sa);
- /* add code points with hardcoded properties, plus the ones following them */
- /* (none right now, see comment below) */
- /*
- * Omit code points with hardcoded specialcasing properties
- * because we do not build property UnicodeSets for them right now.
- */
- }
- /* data access primitives --------------------------------------------------- */
- U_CAPI const struct UCaseProps * U_EXPORT2
- ucase_getSingleton(int32_t *pExceptionsLength, int32_t *pUnfoldLength) {
- *pExceptionsLength = UPRV_LENGTHOF(ucase_props_exceptions);
- *pUnfoldLength = UPRV_LENGTHOF(ucase_props_unfold);
- return &ucase_props_singleton;
- }
- U_CFUNC const UTrie2 * U_EXPORT2
- ucase_getTrie() {
- return &ucase_props_singleton.trie;
- }
- #define GET_EXCEPTIONS(csp, props) ((csp)->exceptions+((props)>>UCASE_EXC_SHIFT))
- /* number of bits in an 8-bit integer value */
- static const uint8_t flagsOffset[256]={
- 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
- };
- #define HAS_SLOT(flags, idx) ((flags)&(1<<(idx)))
- #define SLOT_OFFSET(flags, idx) flagsOffset[(flags)&((1<<(idx))-1)]
- /*
- * Get the value of an optional-value slot where HAS_SLOT(excWord, idx).
- *
- * @param excWord (in) initial exceptions word
- * @param idx (in) desired slot index
- * @param pExc16 (in/out) const uint16_t * after excWord=*pExc16++;
- * moved to the last uint16_t of the value, use +1 for beginning of next slot
- * @param value (out) int32_t or uint32_t output if hasSlot, otherwise not modified
- */
- #define GET_SLOT_VALUE(excWord, idx, pExc16, value) UPRV_BLOCK_MACRO_BEGIN { \
- if(((excWord)&UCASE_EXC_DOUBLE_SLOTS)==0) { \
- (pExc16)+=SLOT_OFFSET(excWord, idx); \
- (value)=*pExc16; \
- } else { \
- (pExc16)+=2*SLOT_OFFSET(excWord, idx); \
- (value)=*pExc16++; \
- (value)=((value)<<16)|*pExc16; \
- } \
- } UPRV_BLOCK_MACRO_END
- /* simple case mappings ----------------------------------------------------- */
- U_CAPI UChar32 U_EXPORT2
- ucase_tolower(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_IS_UPPER_OR_TITLE(props)) {
- c+=UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- uint16_t excWord=*pe++;
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_IS_UPPER_OR_TITLE(props)) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
- GET_SLOT_VALUE(excWord, UCASE_EXC_LOWER, pe, c);
- }
- }
- return c;
- }
- U_CAPI UChar32 U_EXPORT2
- ucase_toupper(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
- c+=UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- uint16_t excWord=*pe++;
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_GET_TYPE(props)==UCASE_LOWER) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
- GET_SLOT_VALUE(excWord, UCASE_EXC_UPPER, pe, c);
- }
- }
- return c;
- }
- U_CAPI UChar32 U_EXPORT2
- ucase_totitle(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
- c+=UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- uint16_t excWord=*pe++;
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_GET_TYPE(props)==UCASE_LOWER) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- int32_t idx;
- if(HAS_SLOT(excWord, UCASE_EXC_TITLE)) {
- idx=UCASE_EXC_TITLE;
- } else if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
- idx=UCASE_EXC_UPPER;
- } else {
- return c;
- }
- GET_SLOT_VALUE(excWord, idx, pe, c);
- }
- return c;
- }
- static const char16_t iDot[2] = { 0x69, 0x307 };
- static const char16_t jDot[2] = { 0x6a, 0x307 };
- static const char16_t iOgonekDot[3] = { 0x12f, 0x307 };
- static const char16_t iDotGrave[3] = { 0x69, 0x307, 0x300 };
- static const char16_t iDotAcute[3] = { 0x69, 0x307, 0x301 };
- static const char16_t iDotTilde[3] = { 0x69, 0x307, 0x303 };
- U_CFUNC void U_EXPORT2
- ucase_addCaseClosure(UChar32 c, const USetAdder *sa) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_GET_TYPE(props)!=UCASE_NONE) {
- /* add the one simple case mapping, no matter what type it is */
- int32_t delta=UCASE_GET_DELTA(props);
- if(delta!=0) {
- sa->add(sa->set, c+delta);
- }
- }
- } else {
- /*
- * c has exceptions, so there may be multiple simple and/or
- * full case mappings. Add them all.
- */
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- uint16_t excWord=*pe++;
- const uint16_t *pe0=pe;
- // Hardcode the case closure of i and its relatives and ignore the
- // data file data for these characters.
- // The Turkic dotless i and dotted I with their case mapping conditions
- // and case folding option make the related characters behave specially.
- // This code matches their closure behavior to their case folding behavior.
- if (excWord&UCASE_EXC_CONDITIONAL_FOLD) {
- // These characters have Turkic case foldings. Hardcode their closure.
- if (c == 0x49) {
- // Regular i and I are in one equivalence class.
- sa->add(sa->set, 0x69);
- return;
- } else if (c == 0x130) {
- // Dotted I is in a class with <0069 0307>
- // (for canonical equivalence with <0049 0307>).
- sa->addString(sa->set, iDot, 2);
- return;
- }
- } else if (c == 0x69) {
- sa->add(sa->set, 0x49);
- return;
- } else if (c == 0x131) {
- // Dotless i is in a class by itself.
- return;
- }
- /* add all simple case mappings */
- for(int32_t idx=UCASE_EXC_LOWER; idx<=UCASE_EXC_TITLE; ++idx) {
- if(HAS_SLOT(excWord, idx)) {
- pe=pe0;
- UChar32 mapping;
- GET_SLOT_VALUE(excWord, idx, pe, mapping);
- sa->add(sa->set, mapping);
- }
- }
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA)) {
- pe=pe0;
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe, delta);
- sa->add(sa->set, (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta);
- }
- /* get the closure string pointer & length */
- const char16_t *closure;
- int32_t closureLength;
- if(HAS_SLOT(excWord, UCASE_EXC_CLOSURE)) {
- pe=pe0;
- GET_SLOT_VALUE(excWord, UCASE_EXC_CLOSURE, pe, closureLength);
- closureLength&=UCASE_CLOSURE_MAX_LENGTH; /* higher bits are reserved */
- closure=(const char16_t *)pe+1; /* behind this slot, unless there are full case mappings */
- } else {
- closureLength=0;
- closure=nullptr;
- }
- /* add the full case folding */
- if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
- pe=pe0;
- int32_t fullLength;
- GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, fullLength);
- /* start of full case mapping strings */
- ++pe;
- fullLength&=0xffff; /* bits 16 and higher are reserved */
- /* skip the lowercase result string */
- pe+=fullLength&UCASE_FULL_LOWER;
- fullLength>>=4;
- /* add the full case folding string */
- int32_t length=fullLength&0xf;
- if(length!=0) {
- sa->addString(sa->set, (const char16_t *)pe, length);
- pe+=length;
- }
- /* skip the uppercase and titlecase strings */
- fullLength>>=4;
- pe+=fullLength&0xf;
- fullLength>>=4;
- pe+=fullLength;
- closure=(const char16_t *)pe; /* behind full case mappings */
- }
- /* add each code point in the closure string */
- for(int32_t idx=0; idx<closureLength;) {
- UChar32 mapping;
- U16_NEXT_UNSAFE(closure, idx, mapping);
- sa->add(sa->set, mapping);
- }
- }
- }
- namespace {
- /**
- * Add the simple case closure mapping,
- * except if there is not actually an scf relationship between the two characters.
- * TODO: Unicode should probably add the corresponding scf mappings.
- * See https://crbug.com/v8/13377 and Unicode-internal PAG issue #23.
- * If & when those scf mappings are added, we should be able to remove all of these exceptions.
- */
- void addOneSimpleCaseClosure(UChar32 c, UChar32 t, const USetAdder *sa) {
- switch (c) {
- case 0x0390:
- if (t == 0x1FD3) { return; }
- break;
- case 0x03B0:
- if (t == 0x1FE3) { return; }
- break;
- case 0x1FD3:
- if (t == 0x0390) { return; }
- break;
- case 0x1FE3:
- if (t == 0x03B0) { return; }
- break;
- case 0xFB05:
- if (t == 0xFB06) { return; }
- break;
- case 0xFB06:
- if (t == 0xFB05) { return; }
- break;
- default:
- break;
- }
- sa->add(sa->set, t);
- }
- } // namespace
- U_CFUNC void U_EXPORT2
- ucase_addSimpleCaseClosure(UChar32 c, const USetAdder *sa) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_GET_TYPE(props)!=UCASE_NONE) {
- /* add the one simple case mapping, no matter what type it is */
- int32_t delta=UCASE_GET_DELTA(props);
- if(delta!=0) {
- sa->add(sa->set, c+delta);
- }
- }
- } else {
- // c has exceptions. Add the mappings relevant for scf=Simple_Case_Folding.
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- uint16_t excWord=*pe++;
- const uint16_t *pe0=pe;
- // Hardcode the case closure of i and its relatives and ignore the
- // data file data for these characters, like in ucase_addCaseClosure().
- if (excWord&UCASE_EXC_CONDITIONAL_FOLD) {
- // These characters have Turkic case foldings. Hardcode their closure.
- if (c == 0x49) {
- // Regular i and I are in one equivalence class.
- sa->add(sa->set, 0x69);
- return;
- } else if (c == 0x130) {
- // For scf=Simple_Case_Folding, dotted I is in a class by itself.
- return;
- }
- } else if (c == 0x69) {
- sa->add(sa->set, 0x49);
- return;
- } else if (c == 0x131) {
- // Dotless i is in a class by itself.
- return;
- }
- // Add all simple case mappings.
- for(int32_t idx=UCASE_EXC_LOWER; idx<=UCASE_EXC_TITLE; ++idx) {
- if(HAS_SLOT(excWord, idx)) {
- pe=pe0;
- UChar32 mapping;
- GET_SLOT_VALUE(excWord, idx, pe, mapping);
- addOneSimpleCaseClosure(c, mapping, sa);
- }
- }
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA)) {
- pe=pe0;
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe, delta);
- UChar32 mapping = (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- addOneSimpleCaseClosure(c, mapping, sa);
- }
- /* get the closure string pointer & length */
- const char16_t *closure;
- int32_t closureLength;
- if(HAS_SLOT(excWord, UCASE_EXC_CLOSURE)) {
- pe=pe0;
- GET_SLOT_VALUE(excWord, UCASE_EXC_CLOSURE, pe, closureLength);
- closureLength&=UCASE_CLOSURE_MAX_LENGTH; /* higher bits are reserved */
- closure=(const char16_t *)pe+1; /* behind this slot, unless there are full case mappings */
- } else {
- closureLength=0;
- closure=nullptr;
- }
- // Skip the full case mappings.
- if(closureLength > 0 && HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
- pe=pe0;
- int32_t fullLength;
- GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, fullLength);
- /* start of full case mapping strings */
- ++pe;
- fullLength&=0xffff; /* bits 16 and higher are reserved */
- // Skip all 4 full case mappings.
- pe+=fullLength&UCASE_FULL_LOWER;
- fullLength>>=4;
- pe+=fullLength&0xf;
- fullLength>>=4;
- pe+=fullLength&0xf;
- fullLength>>=4;
- pe+=fullLength;
- closure=(const char16_t *)pe; /* behind full case mappings */
- }
- // Add each code point in the closure string whose scf maps back to c.
- for(int32_t idx=0; idx<closureLength;) {
- UChar32 mapping;
- U16_NEXT_UNSAFE(closure, idx, mapping);
- addOneSimpleCaseClosure(c, mapping, sa);
- }
- }
- }
- /*
- * compare s, which has a length, with t, which has a maximum length or is NUL-terminated
- * must be length>0 and max>0 and length<=max
- */
- static inline int32_t
- strcmpMax(const char16_t *s, int32_t length, const char16_t *t, int32_t max) {
- int32_t c1, c2;
- max-=length; /* we require length<=max, so no need to decrement max in the loop */
- do {
- c1=*s++;
- c2=*t++;
- if(c2==0) {
- return 1; /* reached the end of t but not of s */
- }
- c1-=c2;
- if(c1!=0) {
- return c1; /* return difference result */
- }
- } while(--length>0);
- /* ends with length==0 */
- if(max==0 || *t==0) {
- return 0; /* equal to length of both strings */
- } else {
- return -max; /* return length difference */
- }
- }
- U_CFUNC UBool U_EXPORT2
- ucase_addStringCaseClosure(const char16_t *s, int32_t length, const USetAdder *sa) {
- int32_t i, start, limit, result, unfoldRows, unfoldRowWidth, unfoldStringWidth;
- if(ucase_props_singleton.unfold==nullptr || s==nullptr) {
- return false; /* no reverse case folding data, or no string */
- }
- if(length<=1) {
- /* the string is too short to find any match */
- /*
- * more precise would be:
- * if(!u_strHasMoreChar32Than(s, length, 1))
- * but this does not make much practical difference because
- * a single supplementary code point would just not be found
- */
- return false;
- }
- const uint16_t *unfold=ucase_props_singleton.unfold;
- unfoldRows=unfold[UCASE_UNFOLD_ROWS];
- unfoldRowWidth=unfold[UCASE_UNFOLD_ROW_WIDTH];
- unfoldStringWidth=unfold[UCASE_UNFOLD_STRING_WIDTH];
- unfold+=unfoldRowWidth;
- if(length>unfoldStringWidth) {
- /* the string is too long to find any match */
- return false;
- }
- /* do a binary search for the string */
- start=0;
- limit=unfoldRows;
- while(start<limit) {
- i=(start+limit)/2;
- const char16_t *p=reinterpret_cast<const char16_t *>(unfold+(i*unfoldRowWidth));
- result=strcmpMax(s, length, p, unfoldStringWidth);
- if(result==0) {
- /* found the string: add each code point, and its case closure */
- UChar32 c;
- for(i=unfoldStringWidth; i<unfoldRowWidth && p[i]!=0;) {
- U16_NEXT_UNSAFE(p, i, c);
- sa->add(sa->set, c);
- ucase_addCaseClosure(c, sa);
- }
- return true;
- } else if(result<0) {
- limit=i;
- } else /* result>0 */ {
- start=i+1;
- }
- }
- return false; /* string not found */
- }
- U_NAMESPACE_BEGIN
- FullCaseFoldingIterator::FullCaseFoldingIterator()
- : unfold(reinterpret_cast<const char16_t *>(ucase_props_singleton.unfold)),
- unfoldRows(unfold[UCASE_UNFOLD_ROWS]),
- unfoldRowWidth(unfold[UCASE_UNFOLD_ROW_WIDTH]),
- unfoldStringWidth(unfold[UCASE_UNFOLD_STRING_WIDTH]),
- currentRow(0),
- rowCpIndex(unfoldStringWidth) {
- unfold+=unfoldRowWidth;
- }
- UChar32
- FullCaseFoldingIterator::next(UnicodeString &full) {
- // Advance past the last-delivered code point.
- const char16_t *p=unfold+(currentRow*unfoldRowWidth);
- if(rowCpIndex>=unfoldRowWidth || p[rowCpIndex]==0) {
- ++currentRow;
- p+=unfoldRowWidth;
- rowCpIndex=unfoldStringWidth;
- }
- if(currentRow>=unfoldRows) { return U_SENTINEL; }
- // Set "full" to the NUL-terminated string in the first unfold column.
- int32_t length=unfoldStringWidth;
- while(length>0 && p[length-1]==0) { --length; }
- full.setTo(false, p, length);
- // Return the code point.
- UChar32 c;
- U16_NEXT_UNSAFE(p, rowCpIndex, c);
- return c;
- }
- namespace LatinCase {
- const int8_t TO_LOWER_NORMAL[LIMIT] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, EXC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 0, 32, 32, 32, 32, 32, 32, 32, EXC,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- EXC, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
- 0, 1, 0, 1, 0, 1, 0, 1, 0, EXC, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, -121, 1, 0, 1, 0, 1, 0, EXC
- };
- const int8_t TO_LOWER_TR_LT[LIMIT] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 32, 32, 32, 32, 32, 32, 32, 32, EXC, EXC, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, EXC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, EXC, EXC, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 0, 32, 32, 32, 32, 32, 32, 32, EXC,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, EXC, 0, 1, 0, 1, 0, EXC, 0,
- EXC, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
- 0, 1, 0, 1, 0, 1, 0, 1, 0, EXC, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0, 1, 0, -121, 1, 0, 1, 0, 1, 0, EXC
- };
- const int8_t TO_UPPER_NORMAL[LIMIT] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, EXC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, EXC,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, 0, -32, -32, -32, -32, -32, -32, -32, 121,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, EXC, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0,
- -1, 0, -1, 0, -1, 0, -1, 0, -1, EXC, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, EXC
- };
- const int8_t TO_UPPER_TR[LIMIT] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, -32, -32, -32, -32, -32, -32, -32, -32, EXC, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, EXC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, EXC,
- -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
- -32, -32, -32, -32, -32, -32, -32, 0, -32, -32, -32, -32, -32, -32, -32, 121,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, EXC, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0,
- -1, 0, -1, 0, -1, 0, -1, 0, -1, EXC, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1,
- 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, EXC
- };
- } // namespace LatinCase
- U_NAMESPACE_END
- /** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
- U_CAPI int32_t U_EXPORT2
- ucase_getType(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- return UCASE_GET_TYPE(props);
- }
- /** @return same as ucase_getType() and set bit 2 if c is case-ignorable */
- U_CAPI int32_t U_EXPORT2
- ucase_getTypeOrIgnorable(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- return UCASE_GET_TYPE_AND_IGNORABLE(props);
- }
- /** @return UCASE_NO_DOT, UCASE_SOFT_DOTTED, UCASE_ABOVE, UCASE_OTHER_ACCENT */
- static inline int32_t
- getDotType(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- return props&UCASE_DOT_MASK;
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- return (*pe>>UCASE_EXC_DOT_SHIFT)&UCASE_DOT_MASK;
- }
- }
- U_CAPI UBool U_EXPORT2
- ucase_isSoftDotted(UChar32 c) {
- return (UBool)(getDotType(c)==UCASE_SOFT_DOTTED);
- }
- U_CAPI UBool U_EXPORT2
- ucase_isCaseSensitive(UChar32 c) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- return (UBool)((props&UCASE_SENSITIVE)!=0);
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- return (UBool)((*pe&UCASE_EXC_SENSITIVE)!=0);
- }
- }
- /* string casing ------------------------------------------------------------ */
- /*
- * These internal functions form the core of string case mappings.
- * They map single code points to result code points or strings and take
- * all necessary conditions (context, locale ID, options) into account.
- *
- * They do not iterate over the source or write to the destination
- * so that the same functions are useful for non-standard string storage,
- * such as in a Replaceable (for Transliterator) or UTF-8/32 strings etc.
- * For the same reason, the "surrounding text" context is passed in as a
- * UCaseContextIterator which does not make any assumptions about
- * the underlying storage.
- *
- * This section contains helper functions that check for conditions
- * in the input text surrounding the current code point
- * according to SpecialCasing.txt.
- *
- * Each helper function gets the index
- * - after the current code point if it looks at following text
- * - before the current code point if it looks at preceding text
- *
- * Unicode 3.2 UAX 21 "Case Mappings" defines the conditions as follows:
- *
- * Final_Sigma
- * C is preceded by a sequence consisting of
- * a cased letter and a case-ignorable sequence,
- * and C is not followed by a sequence consisting of
- * an ignorable sequence and then a cased letter.
- *
- * More_Above
- * C is followed by one or more characters of combining class 230 (ABOVE)
- * in the combining character sequence.
- *
- * After_Soft_Dotted
- * The last preceding character with combining class of zero before C
- * was Soft_Dotted,
- * and there is no intervening combining character class 230 (ABOVE).
- *
- * Before_Dot
- * C is followed by combining dot above (U+0307).
- * Any sequence of characters with a combining class that is neither 0 nor 230
- * may intervene between the current character and the combining dot above.
- *
- * The erratum from 2002-10-31 adds the condition
- *
- * After_I
- * The last preceding base character was an uppercase I, and there is no
- * intervening combining character class 230 (ABOVE).
- *
- * (See Jitterbug 2344 and the comments on After_I below.)
- *
- * Helper definitions in Unicode 3.2 UAX 21:
- *
- * D1. A character C is defined to be cased
- * if it meets any of the following criteria:
- *
- * - The general category of C is Titlecase Letter (Lt)
- * - In [CoreProps], C has one of the properties Uppercase, or Lowercase
- * - Given D = NFD(C), then it is not the case that:
- * D = UCD_lower(D) = UCD_upper(D) = UCD_title(D)
- * (This third criterion does not add any characters to the list
- * for Unicode 3.2. Ignored.)
- *
- * D2. A character C is defined to be case-ignorable
- * if it meets either of the following criteria:
- *
- * - The general category of C is
- * Nonspacing Mark (Mn), or Enclosing Mark (Me), or Format Control (Cf), or
- * Letter Modifier (Lm), or Symbol Modifier (Sk)
- * - C is one of the following characters
- * U+0027 APOSTROPHE
- * U+00AD SOFT HYPHEN (SHY)
- * U+2019 RIGHT SINGLE QUOTATION MARK
- * (the preferred character for apostrophe)
- *
- * D3. A case-ignorable sequence is a sequence of
- * zero or more case-ignorable characters.
- */
- #define is_d(c) ((c)=='d' || (c)=='D')
- #define is_e(c) ((c)=='e' || (c)=='E')
- #define is_i(c) ((c)=='i' || (c)=='I')
- #define is_l(c) ((c)=='l' || (c)=='L')
- #define is_r(c) ((c)=='r' || (c)=='R')
- #define is_t(c) ((c)=='t' || (c)=='T')
- #define is_u(c) ((c)=='u' || (c)=='U')
- #define is_y(c) ((c)=='y' || (c)=='Y')
- #define is_z(c) ((c)=='z' || (c)=='Z')
- /* separator? */
- #define is_sep(c) ((c)=='_' || (c)=='-' || (c)==0)
- /**
- * Requires non-nullptr locale ID but otherwise does the equivalent of
- * checking for language codes as if uloc_getLanguage() were called:
- * Accepts both 2- and 3-letter codes and accepts case variants.
- */
- U_CFUNC int32_t
- ucase_getCaseLocale(const char *locale) {
- /*
- * This function used to use uloc_getLanguage(), but the current code
- * removes the dependency of this low-level code on uloc implementation code
- * and is faster because not the whole locale ID has to be
- * examined and copied/transformed.
- *
- * Because this code does not want to depend on uloc, the caller must
- * pass in a non-nullptr locale, i.e., may need to call uloc_getDefault().
- */
- char c=*locale++;
- // Fastpath for English "en" which is often used for default (=root locale) case mappings,
- // and for Chinese "zh": Very common but no special case mapping behavior.
- // Then check lowercase vs. uppercase to reduce the number of comparisons
- // for other locales without special behavior.
- if(c=='e') {
- /* el or ell? */
- c=*locale++;
- if(is_l(c)) {
- c=*locale++;
- if(is_l(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_GREEK;
- }
- }
- // en, es, ... -> root
- } else if(c=='z') {
- return UCASE_LOC_ROOT;
- #if U_CHARSET_FAMILY==U_ASCII_FAMILY
- } else if(c>='a') { // ASCII a-z = 0x61..0x7a, after A-Z
- #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
- } else if(c<='z') { // EBCDIC a-z = 0x81..0xa9 with two gaps, before A-Z
- #else
- # error Unknown charset family!
- #endif
- // lowercase c
- if(c=='t') {
- /* tr or tur? */
- c=*locale++;
- if(is_u(c)) {
- c=*locale++;
- }
- if(is_r(c)) {
- c=*locale;
- if(is_sep(c)) {
- return UCASE_LOC_TURKISH;
- }
- }
- } else if(c=='a') {
- /* az or aze? */
- c=*locale++;
- if(is_z(c)) {
- c=*locale++;
- if(is_e(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_TURKISH;
- }
- }
- } else if(c=='l') {
- /* lt or lit? */
- c=*locale++;
- if(is_i(c)) {
- c=*locale++;
- }
- if(is_t(c)) {
- c=*locale;
- if(is_sep(c)) {
- return UCASE_LOC_LITHUANIAN;
- }
- }
- } else if(c=='n') {
- /* nl or nld? */
- c=*locale++;
- if(is_l(c)) {
- c=*locale++;
- if(is_d(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_DUTCH;
- }
- }
- } else if(c=='h') {
- /* hy or hye? *not* hyw */
- c=*locale++;
- if(is_y(c)) {
- c=*locale++;
- if(is_e(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_ARMENIAN;
- }
- }
- }
- } else {
- // uppercase c
- // Same code as for lowercase c but also check for 'E'.
- if(c=='T') {
- /* tr or tur? */
- c=*locale++;
- if(is_u(c)) {
- c=*locale++;
- }
- if(is_r(c)) {
- c=*locale;
- if(is_sep(c)) {
- return UCASE_LOC_TURKISH;
- }
- }
- } else if(c=='A') {
- /* az or aze? */
- c=*locale++;
- if(is_z(c)) {
- c=*locale++;
- if(is_e(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_TURKISH;
- }
- }
- } else if(c=='L') {
- /* lt or lit? */
- c=*locale++;
- if(is_i(c)) {
- c=*locale++;
- }
- if(is_t(c)) {
- c=*locale;
- if(is_sep(c)) {
- return UCASE_LOC_LITHUANIAN;
- }
- }
- } else if(c=='E') {
- /* el or ell? */
- c=*locale++;
- if(is_l(c)) {
- c=*locale++;
- if(is_l(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_GREEK;
- }
- }
- } else if(c=='N') {
- /* nl or nld? */
- c=*locale++;
- if(is_l(c)) {
- c=*locale++;
- if(is_d(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_DUTCH;
- }
- }
- } else if(c=='H') {
- /* hy or hye? *not* hyw */
- c=*locale++;
- if(is_y(c)) {
- c=*locale++;
- if(is_e(c)) {
- c=*locale;
- }
- if(is_sep(c)) {
- return UCASE_LOC_ARMENIAN;
- }
- }
- }
- }
- return UCASE_LOC_ROOT;
- }
- /*
- * Is followed by
- * {case-ignorable}* cased
- * ?
- * (dir determines looking forward/backward)
- * If a character is case-ignorable, it is skipped regardless of whether
- * it is also cased or not.
- */
- static UBool
- isFollowedByCasedLetter(UCaseContextIterator *iter, void *context, int8_t dir) {
- UChar32 c;
- if(iter==nullptr) {
- return false;
- }
- for(/* dir!=0 sets direction */; (c=iter(context, dir))>=0; dir=0) {
- int32_t type=ucase_getTypeOrIgnorable(c);
- if(type&4) {
- /* case-ignorable, continue with the loop */
- } else if(type!=UCASE_NONE) {
- return true; /* followed by cased letter */
- } else {
- return false; /* uncased and not case-ignorable */
- }
- }
- return false; /* not followed by cased letter */
- }
- /* Is preceded by Soft_Dotted character with no intervening cc=230 ? */
- static UBool
- isPrecededBySoftDotted(UCaseContextIterator *iter, void *context) {
- UChar32 c;
- int32_t dotType;
- int8_t dir;
- if(iter==nullptr) {
- return false;
- }
- for(dir=-1; (c=iter(context, dir))>=0; dir=0) {
- dotType=getDotType(c);
- if(dotType==UCASE_SOFT_DOTTED) {
- return true; /* preceded by TYPE_i */
- } else if(dotType!=UCASE_OTHER_ACCENT) {
- return false; /* preceded by different base character (not TYPE_i), or intervening cc==230 */
- }
- }
- return false; /* not preceded by TYPE_i */
- }
- /*
- * See Jitterbug 2344:
- * The condition After_I for Turkic-lowercasing of U+0307 combining dot above
- * is checked in ICU 2.0, 2.1, 2.6 but was not in 2.2 & 2.4 because
- * we made those releases compatible with Unicode 3.2 which had not fixed
- * a related bug in SpecialCasing.txt.
- *
- * From the Jitterbug 2344 text:
- * ... this bug is listed as a Unicode erratum
- * from 2002-10-31 at http://www.unicode.org/uni2errata/UnicodeErrata.html
- * <quote>
- * There are two errors in SpecialCasing.txt.
- * 1. Missing semicolons on two lines. ... [irrelevant for ICU]
- * 2. An incorrect context definition. Correct as follows:
- * < 0307; ; 0307; 0307; tr After_Soft_Dotted; # COMBINING DOT ABOVE
- * < 0307; ; 0307; 0307; az After_Soft_Dotted; # COMBINING DOT ABOVE
- * ---
- * > 0307; ; 0307; 0307; tr After_I; # COMBINING DOT ABOVE
- * > 0307; ; 0307; 0307; az After_I; # COMBINING DOT ABOVE
- * where the context After_I is defined as:
- * The last preceding base character was an uppercase I, and there is no
- * intervening combining character class 230 (ABOVE).
- * </quote>
- *
- * Note that SpecialCasing.txt even in Unicode 3.2 described the condition as:
- *
- * # When lowercasing, remove dot_above in the sequence I + dot_above, which will turn into i.
- * # This matches the behavior of the canonically equivalent I-dot_above
- *
- * See also the description in this place in older versions of uchar.c (revision 1.100).
- *
- * Markus W. Scherer 2003-feb-15
- */
- /* Is preceded by base character 'I' with no intervening cc=230 ? */
- static UBool
- isPrecededBy_I(UCaseContextIterator *iter, void *context) {
- UChar32 c;
- int32_t dotType;
- int8_t dir;
- if(iter==nullptr) {
- return false;
- }
- for(dir=-1; (c=iter(context, dir))>=0; dir=0) {
- if(c==0x49) {
- return true; /* preceded by I */
- }
- dotType=getDotType(c);
- if(dotType!=UCASE_OTHER_ACCENT) {
- return false; /* preceded by different base character (not I), or intervening cc==230 */
- }
- }
- return false; /* not preceded by I */
- }
- /* Is followed by one or more cc==230 ? */
- static UBool
- isFollowedByMoreAbove(UCaseContextIterator *iter, void *context) {
- UChar32 c;
- int32_t dotType;
- int8_t dir;
- if(iter==nullptr) {
- return false;
- }
- for(dir=1; (c=iter(context, dir))>=0; dir=0) {
- dotType=getDotType(c);
- if(dotType==UCASE_ABOVE) {
- return true; /* at least one cc==230 following */
- } else if(dotType!=UCASE_OTHER_ACCENT) {
- return false; /* next base character, no more cc==230 following */
- }
- }
- return false; /* no more cc==230 following */
- }
- /* Is followed by a dot above (without cc==230 in between) ? */
- static UBool
- isFollowedByDotAbove(UCaseContextIterator *iter, void *context) {
- UChar32 c;
- int32_t dotType;
- int8_t dir;
- if(iter==nullptr) {
- return false;
- }
- for(dir=1; (c=iter(context, dir))>=0; dir=0) {
- if(c==0x307) {
- return true;
- }
- dotType=getDotType(c);
- if(dotType!=UCASE_OTHER_ACCENT) {
- return false; /* next base character or cc==230 in between */
- }
- }
- return false; /* no dot above following */
- }
- U_CAPI int32_t U_EXPORT2
- ucase_toFullLower(UChar32 c,
- UCaseContextIterator *iter, void *context,
- const char16_t **pString,
- int32_t loc) {
- // The sign of the result has meaning, input must be non-negative so that it can be returned as is.
- U_ASSERT(c >= 0);
- UChar32 result=c;
- // Reset the output pointer in case it was uninitialized.
- *pString=nullptr;
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_IS_UPPER_OR_TITLE(props)) {
- result=c+UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props), *pe2;
- uint16_t excWord=*pe++;
- int32_t full;
- pe2=pe;
- if(excWord&UCASE_EXC_CONDITIONAL_SPECIAL) {
- /* use hardcoded conditions and mappings */
- /*
- * Test for conditional mappings first
- * (otherwise the unconditional default mappings are always taken),
- * then test for characters that have unconditional mappings in SpecialCasing.txt,
- * then get the UnicodeData.txt mappings.
- */
- if( loc==UCASE_LOC_LITHUANIAN &&
- /* base characters, find accents above */
- (((c==0x49 || c==0x4a || c==0x12e) &&
- isFollowedByMoreAbove(iter, context)) ||
- /* precomposed with accent above, no need to find one */
- (c==0xcc || c==0xcd || c==0x128))
- ) {
- /*
- # Lithuanian
- # Lithuanian retains the dot in a lowercase i when followed by accents.
- # Introduce an explicit dot above when lowercasing capital I's and J's
- # whenever there are more accents above.
- # (of the accents used in Lithuanian: grave, acute, tilde above, and ogonek)
- 0049; 0069 0307; 0049; 0049; lt More_Above; # LATIN CAPITAL LETTER I
- 004A; 006A 0307; 004A; 004A; lt More_Above; # LATIN CAPITAL LETTER J
- 012E; 012F 0307; 012E; 012E; lt More_Above; # LATIN CAPITAL LETTER I WITH OGONEK
- 00CC; 0069 0307 0300; 00CC; 00CC; lt; # LATIN CAPITAL LETTER I WITH GRAVE
- 00CD; 0069 0307 0301; 00CD; 00CD; lt; # LATIN CAPITAL LETTER I WITH ACUTE
- 0128; 0069 0307 0303; 0128; 0128; lt; # LATIN CAPITAL LETTER I WITH TILDE
- */
- switch(c) {
- case 0x49: /* LATIN CAPITAL LETTER I */
- *pString=iDot;
- return 2;
- case 0x4a: /* LATIN CAPITAL LETTER J */
- *pString=jDot;
- return 2;
- case 0x12e: /* LATIN CAPITAL LETTER I WITH OGONEK */
- *pString=iOgonekDot;
- return 2;
- case 0xcc: /* LATIN CAPITAL LETTER I WITH GRAVE */
- *pString=iDotGrave;
- return 3;
- case 0xcd: /* LATIN CAPITAL LETTER I WITH ACUTE */
- *pString=iDotAcute;
- return 3;
- case 0x128: /* LATIN CAPITAL LETTER I WITH TILDE */
- *pString=iDotTilde;
- return 3;
- default:
- return 0; /* will not occur */
- }
- /* # Turkish and Azeri */
- } else if(loc==UCASE_LOC_TURKISH && c==0x130) {
- /*
- # I and i-dotless; I-dot and i are case pairs in Turkish and Azeri
- # The following rules handle those cases.
- 0130; 0069; 0130; 0130; tr # LATIN CAPITAL LETTER I WITH DOT ABOVE
- 0130; 0069; 0130; 0130; az # LATIN CAPITAL LETTER I WITH DOT ABOVE
- */
- return 0x69;
- } else if(loc==UCASE_LOC_TURKISH && c==0x307 && isPrecededBy_I(iter, context)) {
- /*
- # When lowercasing, remove dot_above in the sequence I + dot_above, which will turn into i.
- # This matches the behavior of the canonically equivalent I-dot_above
- 0307; ; 0307; 0307; tr After_I; # COMBINING DOT ABOVE
- 0307; ; 0307; 0307; az After_I; # COMBINING DOT ABOVE
- */
- return 0; /* remove the dot (continue without output) */
- } else if(loc==UCASE_LOC_TURKISH && c==0x49 && !isFollowedByDotAbove(iter, context)) {
- /*
- # When lowercasing, unless an I is before a dot_above, it turns into a dotless i.
- 0049; 0131; 0049; 0049; tr Not_Before_Dot; # LATIN CAPITAL LETTER I
- 0049; 0131; 0049; 0049; az Not_Before_Dot; # LATIN CAPITAL LETTER I
- */
- return 0x131;
- } else if(c==0x130) {
- /*
- # Preserve canonical equivalence for I with dot. Turkic is handled below.
- 0130; 0069 0307; 0130; 0130; # LATIN CAPITAL LETTER I WITH DOT ABOVE
- */
- *pString=iDot;
- return 2;
- } else if( c==0x3a3 &&
- !isFollowedByCasedLetter(iter, context, 1) &&
- isFollowedByCasedLetter(iter, context, -1) /* -1=preceded */
- ) {
- /* greek capital sigma maps depending on surrounding cased letters (see SpecialCasing.txt) */
- /*
- # Special case for final form of sigma
- 03A3; 03C2; 03A3; 03A3; Final_Sigma; # GREEK CAPITAL LETTER SIGMA
- */
- return 0x3c2; /* greek small final sigma */
- } else {
- /* no known conditional special case mapping, use a normal mapping */
- }
- } else if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
- GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, full);
- full&=UCASE_FULL_LOWER;
- if(full!=0) {
- /* set the output pointer to the lowercase mapping */
- *pString=reinterpret_cast<const char16_t *>(pe+1);
- /* return the string length */
- return full;
- }
- }
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_IS_UPPER_OR_TITLE(props)) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe2, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
- GET_SLOT_VALUE(excWord, UCASE_EXC_LOWER, pe2, result);
- }
- }
- return (result==c) ? ~result : result;
- }
- /* internal */
- static int32_t
- toUpperOrTitle(UChar32 c,
- UCaseContextIterator *iter, void *context,
- const char16_t **pString,
- int32_t loc,
- UBool upperNotTitle) {
- // The sign of the result has meaning, input must be non-negative so that it can be returned as is.
- U_ASSERT(c >= 0);
- UChar32 result=c;
- // Reset the output pointer in case it was uninitialized.
- *pString=nullptr;
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
- result=c+UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props), *pe2;
- uint16_t excWord=*pe++;
- int32_t full, idx;
- pe2=pe;
- if(excWord&UCASE_EXC_CONDITIONAL_SPECIAL) {
- /* use hardcoded conditions and mappings */
- if(loc==UCASE_LOC_TURKISH && c==0x69) {
- /*
- # Turkish and Azeri
- # I and i-dotless; I-dot and i are case pairs in Turkish and Azeri
- # The following rules handle those cases.
- # When uppercasing, i turns into a dotted capital I
- 0069; 0069; 0130; 0130; tr; # LATIN SMALL LETTER I
- 0069; 0069; 0130; 0130; az; # LATIN SMALL LETTER I
- */
- return 0x130;
- } else if(loc==UCASE_LOC_LITHUANIAN && c==0x307 && isPrecededBySoftDotted(iter, context)) {
- /*
- # Lithuanian
- # Lithuanian retains the dot in a lowercase i when followed by accents.
- # Remove DOT ABOVE after "i" with upper or titlecase
- 0307; 0307; ; ; lt After_Soft_Dotted; # COMBINING DOT ABOVE
- */
- return 0; /* remove the dot (continue without output) */
- } else if(c==0x0587) {
- // See ICU-13416:
- // և ligature ech-yiwn
- // uppercases to ԵՒ=ech+yiwn by default and in Western Armenian,
- // but to ԵՎ=ech+vew in Eastern Armenian.
- if(loc==UCASE_LOC_ARMENIAN) {
- *pString=upperNotTitle ? u"ԵՎ" : u"Եվ";
- } else {
- *pString=upperNotTitle ? u"ԵՒ" : u"Եւ";
- }
- return 2;
- } else {
- /* no known conditional special case mapping, use a normal mapping */
- }
- } else if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
- GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, full);
- /* start of full case mapping strings */
- ++pe;
- /* skip the lowercase and case-folding result strings */
- pe+=full&UCASE_FULL_LOWER;
- full>>=4;
- pe+=full&0xf;
- full>>=4;
- if(upperNotTitle) {
- full&=0xf;
- } else {
- /* skip the uppercase result string */
- pe+=full&0xf;
- full=(full>>4)&0xf;
- }
- if(full!=0) {
- /* set the output pointer to the result string */
- *pString=reinterpret_cast<const char16_t *>(pe);
- /* return the string length */
- return full;
- }
- }
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_GET_TYPE(props)==UCASE_LOWER) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe2, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- if(!upperNotTitle && HAS_SLOT(excWord, UCASE_EXC_TITLE)) {
- idx=UCASE_EXC_TITLE;
- } else if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
- /* here, titlecase is same as uppercase */
- idx=UCASE_EXC_UPPER;
- } else {
- return ~c;
- }
- GET_SLOT_VALUE(excWord, idx, pe2, result);
- }
- return (result==c) ? ~result : result;
- }
- U_CAPI int32_t U_EXPORT2
- ucase_toFullUpper(UChar32 c,
- UCaseContextIterator *iter, void *context,
- const char16_t **pString,
- int32_t caseLocale) {
- return toUpperOrTitle(c, iter, context, pString, caseLocale, true);
- }
- U_CAPI int32_t U_EXPORT2
- ucase_toFullTitle(UChar32 c,
- UCaseContextIterator *iter, void *context,
- const char16_t **pString,
- int32_t caseLocale) {
- return toUpperOrTitle(c, iter, context, pString, caseLocale, false);
- }
- /* case folding ------------------------------------------------------------- */
- /*
- * Case folding is similar to lowercasing.
- * The result may be a simple mapping, i.e., a single code point, or
- * a full mapping, i.e., a string.
- * If the case folding for a code point is the same as its simple (1:1) lowercase mapping,
- * then only the lowercase mapping is stored.
- *
- * Some special cases are hardcoded because their conditions cannot be
- * parsed and processed from CaseFolding.txt.
- *
- * Unicode 3.2 CaseFolding.txt specifies for its status field:
- # C: common case folding, common mappings shared by both simple and full mappings.
- # F: full case folding, mappings that cause strings to grow in length. Multiple characters are separated by spaces.
- # S: simple case folding, mappings to single characters where different from F.
- # T: special case for uppercase I and dotted uppercase I
- # - For non-Turkic languages, this mapping is normally not used.
- # - For Turkic languages (tr, az), this mapping can be used instead of the normal mapping for these characters.
- #
- # Usage:
- # A. To do a simple case folding, use the mappings with status C + S.
- # B. To do a full case folding, use the mappings with status C + F.
- #
- # The mappings with status T can be used or omitted depending on the desired case-folding
- # behavior. (The default option is to exclude them.)
- * Unicode 3.2 has 'T' mappings as follows:
- 0049; T; 0131; # LATIN CAPITAL LETTER I
- 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE
- * while the default mappings for these code points are:
- 0049; C; 0069; # LATIN CAPITAL LETTER I
- 0130; F; 0069 0307; # LATIN CAPITAL LETTER I WITH DOT ABOVE
- * U+0130 has no simple case folding (simple-case-folds to itself).
- */
- /* return the simple case folding mapping for c */
- U_CAPI UChar32 U_EXPORT2
- ucase_fold(UChar32 c, uint32_t options) {
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_IS_UPPER_OR_TITLE(props)) {
- c+=UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
- uint16_t excWord=*pe++;
- int32_t idx;
- if(excWord&UCASE_EXC_CONDITIONAL_FOLD) {
- /* special case folding mappings, hardcoded */
- if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
- /* default mappings */
- if(c==0x49) {
- /* 0049; C; 0069; # LATIN CAPITAL LETTER I */
- return 0x69;
- } else if(c==0x130) {
- /* no simple case folding for U+0130 */
- return c;
- }
- } else {
- /* Turkic mappings */
- if(c==0x49) {
- /* 0049; T; 0131; # LATIN CAPITAL LETTER I */
- return 0x131;
- } else if(c==0x130) {
- /* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
- return 0x69;
- }
- }
- }
- if((excWord&UCASE_EXC_NO_SIMPLE_CASE_FOLDING)!=0) {
- return c;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_IS_UPPER_OR_TITLE(props)) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_FOLD)) {
- idx=UCASE_EXC_FOLD;
- } else if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
- idx=UCASE_EXC_LOWER;
- } else {
- return c;
- }
- GET_SLOT_VALUE(excWord, idx, pe, c);
- }
- return c;
- }
- /*
- * Issue for canonical caseless match (UAX #21):
- * Turkic casefolding (using "T" mappings in CaseFolding.txt) does not preserve
- * canonical equivalence, unlike default-option casefolding.
- * For example, I-grave and I + grave fold to strings that are not canonically
- * equivalent.
- * For more details, see the comment in unorm_compare() in unorm.cpp
- * and the intermediate prototype changes for Jitterbug 2021.
- * (For example, revision 1.104 of uchar.c and 1.4 of CaseFolding.txt.)
- *
- * This did not get fixed because it appears that it is not possible to fix
- * it for uppercase and lowercase characters (I-grave vs. i-grave)
- * together in a way that they still fold to common result strings.
- */
- U_CAPI int32_t U_EXPORT2
- ucase_toFullFolding(UChar32 c,
- const char16_t **pString,
- uint32_t options) {
- // The sign of the result has meaning, input must be non-negative so that it can be returned as is.
- U_ASSERT(c >= 0);
- UChar32 result=c;
- // Reset the output pointer in case it was uninitialized.
- *pString=nullptr;
- uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
- if(!UCASE_HAS_EXCEPTION(props)) {
- if(UCASE_IS_UPPER_OR_TITLE(props)) {
- result=c+UCASE_GET_DELTA(props);
- }
- } else {
- const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props), *pe2;
- uint16_t excWord=*pe++;
- int32_t full, idx;
- pe2=pe;
- if(excWord&UCASE_EXC_CONDITIONAL_FOLD) {
- /* use hardcoded conditions and mappings */
- if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
- /* default mappings */
- if(c==0x49) {
- /* 0049; C; 0069; # LATIN CAPITAL LETTER I */
- return 0x69;
- } else if(c==0x130) {
- /* 0130; F; 0069 0307; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
- *pString=iDot;
- return 2;
- }
- } else {
- /* Turkic mappings */
- if(c==0x49) {
- /* 0049; T; 0131; # LATIN CAPITAL LETTER I */
- return 0x131;
- } else if(c==0x130) {
- /* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
- return 0x69;
- }
- }
- } else if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
- GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, full);
- /* start of full case mapping strings */
- ++pe;
- /* skip the lowercase result string */
- pe+=full&UCASE_FULL_LOWER;
- full=(full>>4)&0xf;
- if(full!=0) {
- /* set the output pointer to the result string */
- *pString=reinterpret_cast<const char16_t *>(pe);
- /* return the string length */
- return full;
- }
- }
- if((excWord&UCASE_EXC_NO_SIMPLE_CASE_FOLDING)!=0) {
- return ~c;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_DELTA) && UCASE_IS_UPPER_OR_TITLE(props)) {
- int32_t delta;
- GET_SLOT_VALUE(excWord, UCASE_EXC_DELTA, pe2, delta);
- return (excWord&UCASE_EXC_DELTA_IS_NEGATIVE)==0 ? c+delta : c-delta;
- }
- if(HAS_SLOT(excWord, UCASE_EXC_FOLD)) {
- idx=UCASE_EXC_FOLD;
- } else if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
- idx=UCASE_EXC_LOWER;
- } else {
- return ~c;
- }
- GET_SLOT_VALUE(excWord, idx, pe2, result);
- }
- return (result==c) ? ~result : result;
- }
- /* case mapping properties API ---------------------------------------------- */
- /* public API (see uchar.h) */
- U_CAPI UBool U_EXPORT2
- u_isULowercase(UChar32 c) {
- return (UBool)(UCASE_LOWER==ucase_getType(c));
- }
- U_CAPI UBool U_EXPORT2
- u_isUUppercase(UChar32 c) {
- return (UBool)(UCASE_UPPER==ucase_getType(c));
- }
- /* Transforms the Unicode character to its lower case equivalent.*/
- U_CAPI UChar32 U_EXPORT2
- u_tolower(UChar32 c) {
- return ucase_tolower(c);
- }
- /* Transforms the Unicode character to its upper case equivalent.*/
- U_CAPI UChar32 U_EXPORT2
- u_toupper(UChar32 c) {
- return ucase_toupper(c);
- }
- /* Transforms the Unicode character to its title case equivalent.*/
- U_CAPI UChar32 U_EXPORT2
- u_totitle(UChar32 c) {
- return ucase_totitle(c);
- }
- /* return the simple case folding mapping for c */
- U_CAPI UChar32 U_EXPORT2
- u_foldCase(UChar32 c, uint32_t options) {
- return ucase_fold(c, options);
- }
- U_CFUNC int32_t U_EXPORT2
- ucase_hasBinaryProperty(UChar32 c, UProperty which) {
- /* case mapping properties */
- const char16_t *resultString;
- switch(which) {
- case UCHAR_LOWERCASE:
- return (UBool)(UCASE_LOWER==ucase_getType(c));
- case UCHAR_UPPERCASE:
- return (UBool)(UCASE_UPPER==ucase_getType(c));
- case UCHAR_SOFT_DOTTED:
- return ucase_isSoftDotted(c);
- case UCHAR_CASE_SENSITIVE:
- return ucase_isCaseSensitive(c);
- case UCHAR_CASED:
- return (UBool)(UCASE_NONE!=ucase_getType(c));
- case UCHAR_CASE_IGNORABLE:
- return (UBool)(ucase_getTypeOrIgnorable(c)>>2);
- /*
- * Note: The following Changes_When_Xyz are defined as testing whether
- * the NFD form of the input changes when Xyz-case-mapped.
- * However, this simpler implementation of these properties,
- * ignoring NFD, passes the tests.
- * The implementation needs to be changed if the tests start failing.
- * When that happens, optimizations should be used to work with the
- * per-single-code point ucase_toFullXyz() functions unless
- * the NFD form has more than one code point,
- * and the property starts set needs to be the union of the
- * start sets for normalization and case mappings.
- */
- case UCHAR_CHANGES_WHEN_LOWERCASED:
- return (UBool)(ucase_toFullLower(c, nullptr, nullptr, &resultString, UCASE_LOC_ROOT)>=0);
- case UCHAR_CHANGES_WHEN_UPPERCASED:
- return (UBool)(ucase_toFullUpper(c, nullptr, nullptr, &resultString, UCASE_LOC_ROOT)>=0);
- case UCHAR_CHANGES_WHEN_TITLECASED:
- return (UBool)(ucase_toFullTitle(c, nullptr, nullptr, &resultString, UCASE_LOC_ROOT)>=0);
- /* case UCHAR_CHANGES_WHEN_CASEFOLDED: -- in uprops.c */
- case UCHAR_CHANGES_WHEN_CASEMAPPED:
- return (UBool)(
- ucase_toFullLower(c, nullptr, nullptr, &resultString, UCASE_LOC_ROOT)>=0 ||
- ucase_toFullUpper(c, nullptr, nullptr, &resultString, UCASE_LOC_ROOT)>=0 ||
- ucase_toFullTitle(c, nullptr, nullptr, &resultString, UCASE_LOC_ROOT)>=0);
- default:
- return false;
- }
- }
|