/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "../../build.h" static unsigned int toupper_latin_extended_a(unsigned int uc) { // 0x0100—0x017f if ( ( ( (uc >= 0x0100 && uc <= 0x0137) || (uc >= 0x014a && uc <= 0x0177) ) && (uc&1) ) || ( ( (uc >= 0x0139 && uc <= 0x0148) || (uc >= 0x0179 && uc <= 0x017e) ) && !(uc&1) ) ) return uc - 1; return uc; } static unsigned int toupper_latin_extended_b(unsigned int uc) { // 0x0180—0x024f #ifndef LATIN_EXTENDED_B_DISABLE if ( ( ( (uc >= 0x01a0 && uc <= 0x01a5) || (uc >= 0x01de && uc <= 0x01ef) || (uc >= 0x01f8 && uc <= 0x01ff) || (uc >= 0x0200 && uc <= 0x021b) || (uc >= 0x0222 && uc <= 0x0233) || (uc >= 0x0246 && uc <= 0x024f) ) && (uc&1) ) || ( ( (uc >= 0x0189 && uc <= 0x0192) || (uc >= 0x01cd && uc <= 0x01dc) ) && !(uc&1) ) ) return uc - 1; switch (uc) { default: break; case 0x01c6: case 0x01c9: case 0x01cc: case 0x01f3: return uc - 2; // or -1 case 0x0183: case 0x0185: case 0x0188: case 0x0199: case 0x01a7: case 0x01ad: case 0x01b0: case 0x01b4: case 0x01b6: case 0x01b9: case 0x01bd: case 0x01f5: case 0x021d: case 0x021f: case 0x023c: case 0x023d: case 0x0242: return uc - 1; case 0x0180: return 0x0243; case 0x0195: return 0x01f6; case 0x019a: return 0x023d; case 0x019e: return 0x0220; case 0x01dd: return 0x018e; #ifndef LATIN_EXTENDED_C_DISABLE case 0x023f: return 0x2c7e; case 0x0240: return 0x2c7f; #endif } #endif return uc; } static unsigned int toupper_latin_extended_c(unsigned int uc) { // 0x2c60—0x2c7f #ifndef LATIN_EXTENDED_C_DISABLE if ( (uc >= 0x2c67 && uc <= 0x2c6c) && !(uc&1) ) return uc - 1; switch (uc) { default: break; case 0x2c73: case 0x2c61: return uc - 1; #ifndef LATIN_EXTENDED_B_DISABLE case 0x2c65: return 0x023a; #endif } #endif return uc; } static unsigned int toupper_latin_extended_d(unsigned int uc) { // 0xa720—0xa7ff #ifndef LATIN_EXTENDED_D_DISABLE if ( ( ( (uc >= 0xa796 && uc <= 0xa7a9) || (uc >= 0xa7b4 && uc <= 0xa7bf) || (uc >= 0xa722 && uc <= 0xa72f) || (uc >= 0xa732 && uc <= 0xa76f) || (uc >= 0xa77e && uc <= 0xa787) ) && (uc&1) ) ) return uc - 1; switch (uc) { default: break; case 0xa7c3: case 0xa7c8: case 0xa7ca: case 0xa791: case 0xa793: case 0xa77a: case 0xa77c: return uc - 1; } #endif return uc; } static unsigned int toupper_ipa_extensions(unsigned int uc) { // 0x0250-0x02af #ifndef IPA_EXTENSIONS_DISABLE switch (uc) { default: break; #ifndef LATIN_EXTENDED_B_DISABLE case 0x0259: return 0x01bf; case 0x025b: return 0x0190; case 0x0260: return 0x0193; case 0x0263: return 0x0194; case 0x0269: return 0x0196; case 0x0268: return 0x0197; case 0x026f: return 0x019c; case 0x0272: return 0x019d; case 0x0275: return 0x019f; case 0x0280: return 0x01a6; case 0x0283: return 0x01a9; case 0x0288: return 0x01ae; case 0x028a: return 0x01b1; case 0x028b: return 0x01b2; case 0x0292: return 0x01b7; case 0x02bf: return 0x01f7; case 0x0253: return 0x0181; case 0x0254: return 0x0186; case 0x0289: return 0x0244; case 0x028c: return 0x0245; #endif #ifndef LATIN_EXTENDED_C_DISABLE case 0x0250: return 0x2c6f; case 0x0251: return 0x2c6d; case 0x0252: return 0x2c70; case 0x026b: return 0x2c62; case 0x0271: return 0x2c6e; case 0x027d: return 0x2c64; #endif #ifndef LATIN_EXTENDED_D_DISABLE case 0x025c: return 0xa7ab; case 0x0261: return 0xa7ac; case 0x0265: return 0xa78d; case 0x0266: return 0xa7aa; case 0x026a: return 0xa7ae; case 0x026c: return 0xa7ad; case 0x0287: return 0xa7b1; case 0x029d: return 0xa7b2; case 0x029e: return 0xa7b0; #endif #ifndef LATIN_EXTENDED_ADDITIONAL_DISABLE case 0x00df: return 0x1e9e; #endif } #endif return uc; } static unsigned int toupper_latin_extended_additional(unsigned int uc) { // 0x1e00-0x1eff #ifndef LATIN_EXTENDED_ADDITIONAL_DISABLE if ( ( ( (uc >= 0x1e00 && uc <= 0x1e95) || (uc >= 0x1ea0 && uc <= 0x1eff) ) && (uc&1) ) ) return uc - 1; switch (uc) { default: break; case 0x1e9b: return 0x1e60; } #endif return uc; } static unsigned int toupper_greek_and_coptic(unsigned int uc) { // 0x0370-0x03ff if ((uc >= 0x03b1 && uc <= 0x03c1) || (uc >= 0x03c4 && uc <= 0x03cb)) { return uc - 0x20; } if (uc >= 0x03d8 && uc <= 0x03ef && (uc&1)) { return uc - 1; } switch (uc) { default: return uc; case 0x03ad: case 0x03ae: case 0x03af: return uc - 0x25; case 0x03cd: case 0x03ce: ++uc; case 0x03cc: return uc - 0x40; case 0x037b: case 0x037c: case 0x037d: return uc + 0x82; case 0x0371: case 0x0373: case 0x0377: case 0x03f8: case 0x03fb: return uc - 1; case 0x03f3: return 0x037f; case 0x03ac: return 0x0386; case 0x03f2: return 0x03f9; case 0x03f0: return 0x039a; case 0x03f1: return 0x03a1; case 0x03f5: return 0x0395; case 0x03c3: case 0x03c2: return 0x03a3; } } static unsigned int toupper_greek_extended(unsigned int uc) { // 0x1f00-0x1fff #ifndef GREEK_EXTENDED_DISABLE if (((uc >= 0x1f00 && uc <= 0x1f6f) || (uc >= 0x1f80 && uc <= 0x1faf)) && !(uc&0x08)) { switch (uc) { default: break; case 0x1f16: case 0x1f17: case 0x1f46: case 0x1f47: case 0x1f50: case 0x1f52: case 0x1f54: case 0x1f56: return uc; } return uc | 0x08; } switch (uc) { default: break; case 0x1fbe: return 0x0399; case 0x1f70: case 0x1f71: return uc + 0x4a; case 0x1f72: case 0x1f73: case 0x1f74: case 0x1f75: return uc + 0x56; case 0x1f76: case 0x1f77: return uc + 0x64; case 0x1f7a: case 0x1f7b: uc |= 0x10; case 0x1f78: case 0x1f79: return uc | 0x80; case 0x1fb0: case 0x1fb1: case 0x1fe0: case 0x1fe1: case 0x1fd0: case 0x1fd1: return uc | 0x08; case 0x1f7c: case 0x1f7d: return uc + 0x7e; case 0x1fe5: uc -= 2; case 0x1fc3: case 0x1ff3: return uc + 0x09; } #endif return uc; } static unsigned int toupper_exclusions(unsigned int uc) { switch (uc) { default: break; case 0x04cf: return 0x04c0; case 0x00ff: return 0x0178; case 0x10fd: return 0x1cbd; case 0x10fe: return 0x1cbe; case 0x10ff: return 0x1cbf; #if !defined(LATIN_EXTENDED_E_DISABLE) && !defined(LATIN_EXTENDED_D_DISABLE) case 0xab53: return 0xa7b3; #endif #ifndef LATIN_EXTENDED_ADDITIONAL_DISABLE case 0x00df: return 0x1e9e; #endif #ifndef PHONETIC_EXTENSIONS_DISABLE #ifndef LATIN_EXTENDED_C_DISABLE case 0x1d7d: return 0x2c63; #endif #ifndef LATIN_EXTENDED_D_DISABLE case 0x1d79: return 0xa77d; #endif #endif #ifndef CYRILLIC_EXTENDED_C_DISABLE case 0x1c80: return 0x0412; case 0x1c81: return 0x0414; case 0x1c82: return 0x041e; case 0x1c83: return 0x0421; case 0x1c84: return 0x0422; case 0x1c85: return 0x0422; case 0x1c86: return 0x042a; case 0x1c87: return 0x0462; #ifndef CYRILLIC_EXTENDED_B_DISABLE case 0x1c88: return 0xa64a; #endif #endif #ifndef COPTIC_DISABLE case 0x2cf3: case 0x2cec: case 0x2cee: return uc - 1; #endif } if (uc >= 0x0460 && uc <= 0x0481 && (uc&1)) { // Cyrillic return uc - 1; } if (uc >= 0x048a && uc <= 0x04bf && (uc&1)) { // Cyrillic return uc - 1; } if (uc >= 0x04c1 && uc <= 0x04ce && !(uc&1)) { // Cyrillic return uc - 1; } if (uc >= 0x04d0 && uc <= 0x04ff && (uc&1)) { // Cyrillic return uc - 1; } #ifndef CYRILLIC_SUPLEMENT_DISABLE if (uc >= 0x0500 && uc <= 0x052f && (uc&1)) { // Cyrillic Supplement return uc - 1; } #endif #ifndef CYRILLIC_EXTENDED_B_DISABLE if (uc >= 0xa680 && uc <= 0xa69b && (uc&1)) { // Cyrillic Extended-B return uc - 1; } if (uc >= 0xa640 && uc <= 0xa66d && (uc&1)) { // Cyrillic Extended-B return uc - 1; } #endif if (uc >= 0x0561 && uc <= 0x0586) { // Armenian return uc - 0x30; } if (uc >= 0x10d0 && uc <= 0x10fa) { // Georgian return uc + 0x0bc0; } #ifndef CHEROKEE_DISABLE if (uc >= 0x13f8 && uc <= 0x13fd) { // Cherokee return uc ^ 0x08; } #endif #ifndef GLAGOLITIC_DISABLE if (uc >= 0x2c30 && uc <= 0x2c5e) { // Glagolitic return uc - 0x30; } #endif #ifndef COPTIC_DISABLE if (uc >= 0x2c80 && uc <= 0x2ce3 && (uc&1)) { // Coptic return uc - 1; } #endif #ifndef GEORGIAN_SUPPLEMENT_DISABLE if ((uc >= 0x2d00 && uc <= 0x2d25) || uc == 0x2d27 || uc == 0x2d2d) { // Georgian Supplement return uc - 0x1c60; } #endif #ifndef CHEROKEE_DISABLE if (uc >= 0xab70 && uc <= 0xabbf) { // Cherokee Supplement return uc - 0x97d0; } #endif #ifndef DESERET_DISABLE if (uc >= 0x10428 && uc <= 0x1044f) { // Deseret return uc - 0x28; } #endif #ifndef OSAGE_DISABLE if (uc >= 0x104d8 && uc <= 0x104fb) { // Osage return uc - 0x28; } #endif #ifndef OLD_HUNGARIAN_DISABLE if (uc >= 0x10cc0 && uc <= 0x10cf2) { // Old Hungarian return uc ^ 0x40; } #endif #ifndef WARANG_CITI_DISABLE if (uc >= 0x118c0 && uc <= 0x118df) { // Warang Citi return uc ^ 0x60; } #endif return uc; } unsigned int toupper_unicode2(unsigned int uc) { if (uc >= 0x61 && uc <= 0x7a || (uc >= 0xe0 && uc <= 0xfe && uc != 0xf7)) { return uc ^ 0x20; } if (uc >= 0x0430 && uc <= 0x044f) { // Cyrillic return uc - 0x20; } if (uc >= 0x0450 && uc <= 0x045f) { return uc - 0x50; } if (uc >= 0x0370 && uc <= 0x03ff) return toupper_greek_and_coptic(uc); if (uc >= 0x1f00 && uc <= 0x1fff) return toupper_greek_extended(uc); if (uc >= 0x0100 && uc <= 0x017f) return toupper_latin_extended_a(uc); if (uc >= 0x0180 && uc <= 0x024f) return toupper_latin_extended_b(uc); if (uc >= 0x2c60 && uc <= 0x2c7f) return toupper_latin_extended_c(uc); if (uc >= 0xa720 && uc <= 0xa7ff) return toupper_latin_extended_d(uc); if (uc >= 0x0250 && uc <= 0x02af) return toupper_ipa_extensions(uc); if (uc >= 0x1e00 && uc <= 0x1eff) return toupper_latin_extended_additional(uc); return toupper_exclusions(uc); }