398 lines
10 KiB
C
398 lines
10 KiB
C
/* This software is licensed by the MIT License, see LICENSE file */
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
#include "../../build.h"
|
|
|
|
static unsigned int tolower_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;
|
|
|
|
switch (uc) { default: break;
|
|
case 0x0178: return 0x00ff;
|
|
}
|
|
|
|
return uc;
|
|
}
|
|
|
|
static unsigned int tolower_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 0x01c4:
|
|
case 0x01c5: return 0x01c6;
|
|
case 0x01c7:
|
|
case 0x01c8: return 0x01c9;
|
|
case 0x01ca:
|
|
case 0x01cb: return 0x01cc;
|
|
case 0x01f1:
|
|
case 0x01f2: return 0x01f3;
|
|
|
|
case 0x01a8:
|
|
case 0x01ac:
|
|
case 0x01af:
|
|
case 0x01b3:
|
|
case 0x01b5:
|
|
case 0x01b8:
|
|
case 0x01bc:
|
|
case 0x0182:
|
|
case 0x0184:
|
|
case 0x0187:
|
|
case 0x0198:
|
|
case 0x01f4:
|
|
case 0x021c:
|
|
case 0x021e:
|
|
case 0x023b:
|
|
case 0x023e:
|
|
case 0x0241: return uc + 1;
|
|
|
|
case 0x018e: return 0x01dd;
|
|
case 0x01f6: return 0x0195;
|
|
case 0x0220: return 0x019e;
|
|
case 0x023d: return 0x019a;
|
|
case 0x0243: return 0x0180;
|
|
#ifndef IPA_EXTENSIONS_DISABLE
|
|
case 0x0181: return 0x0253;
|
|
case 0x0186: return 0x0254;
|
|
case 0x0190: return 0x025b;
|
|
case 0x0193: return 0x0260;
|
|
case 0x0194: return 0x0263;
|
|
case 0x0196: return 0x0269;
|
|
case 0x0197: return 0x0268;
|
|
case 0x019c: return 0x026f;
|
|
case 0x019d: return 0x0272;
|
|
case 0x019f: return 0x0275;
|
|
case 0x01a6: return 0x0280;
|
|
case 0x01a9: return 0x0283;
|
|
case 0x01ae: return 0x0288;
|
|
case 0x01b1: return 0x028a;
|
|
case 0x01b2: return 0x028b;
|
|
case 0x01b7: return 0x0292;
|
|
case 0x01bf: return 0x0259;
|
|
case 0x01f7: return 0x02bf;
|
|
case 0x0244: return 0x0289;
|
|
case 0x0245: return 0x028c;
|
|
#endif
|
|
#ifndef LATIN_EXTENDED_C_DISABLE
|
|
case 0x023a: return 0x2c65;
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
return uc;
|
|
}
|
|
|
|
static unsigned int tolower_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 0x2c72:
|
|
case 0x2c60: return uc + 1;
|
|
|
|
#ifndef IPA_EXTENSIONS_DISABLE
|
|
case 0x2c62: return 0x026b;
|
|
case 0x2c64: return 0x027d;
|
|
case 0x2c6d: return 0x0251;
|
|
case 0x2c6e: return 0x0271;
|
|
case 0x2c6f: return 0x0250;
|
|
case 0x2c70: return 0x0252;
|
|
#endif
|
|
#ifndef PHONETIC_EXTENSIONS_DISABLE
|
|
case 0x2c63: return 0x1d7d;
|
|
#endif
|
|
#ifndef LATIN_EXTENDED_B_DISABLE
|
|
case 0x2c7e: return 0x023f;
|
|
case 0x2c7f: return 0x0240;
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
return uc;
|
|
}
|
|
|
|
static unsigned int tolower_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 0xa779:
|
|
case 0xa77b:
|
|
case 0xa790:
|
|
case 0xa792:
|
|
case 0xa7c2:
|
|
case 0xa7c7:
|
|
case 0xa7c9: return uc + 1;
|
|
|
|
#ifndef PHONETIC_EXTENSIONS_DISABLE
|
|
case 0xa77d: return 0x1d79;
|
|
#endif
|
|
#ifndef IPA_EXTENSIONS_DISABLE
|
|
case 0xa78d: return 0x0265;
|
|
case 0xa7aa: return 0x0266;
|
|
case 0xa7ab: return 0x025c;
|
|
case 0xa7ac: return 0x0261;
|
|
case 0xa7ad: return 0x026c;
|
|
case 0xa7ae: return 0x026a;
|
|
case 0xa7b1: return 0x0287;
|
|
case 0xa7b2: return 0x029d;
|
|
case 0xa7b0: return 0x029e;
|
|
#endif
|
|
#ifndef LATIN_EXTENDED_E_DISABLE
|
|
case 0xa7b3: return 0xab53;
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
return uc;
|
|
}
|
|
|
|
static unsigned int tolower_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 0x1e9e: return 0x00df;
|
|
}
|
|
#endif
|
|
|
|
return uc;
|
|
}
|
|
|
|
static unsigned int tolower_greek_and_coptic(unsigned int uc) { // 0x0370-0x03ff
|
|
|
|
if ((uc >= 0x0391 && uc <= 0x03a1) || (uc >= 0x03a4 && uc <= 0x03ab)) {
|
|
return uc + 0x20;
|
|
}
|
|
|
|
if (uc >= 0x03d8 && uc <= 0x03ef && !(uc&1)) {
|
|
return uc + 1;
|
|
}
|
|
|
|
switch (uc) { default: return uc;
|
|
case 0x0388:
|
|
case 0x0389:
|
|
case 0x038a: return uc + 0x25;
|
|
|
|
case 0x038e:
|
|
case 0x038f: --uc;
|
|
case 0x038c: return uc + 0x40;
|
|
|
|
case 0x03fd:
|
|
case 0x03fe:
|
|
case 0x03ff: return uc - 0x82;
|
|
|
|
case 0x0370:
|
|
case 0x0372:
|
|
case 0x0376:
|
|
case 0x03f7:
|
|
case 0x03fa: return uc + 1;
|
|
|
|
case 0x037f: return 0x03f3;
|
|
case 0x0386: return 0x03ac;
|
|
case 0x03f9: return 0x03f2;
|
|
case 0x03f4: return 0x03b8;
|
|
case 0x03a3: return 0x03c3;
|
|
}
|
|
}
|
|
|
|
static unsigned int tolower_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 0x1f1e:
|
|
case 0x1f1f:
|
|
case 0x1f4e:
|
|
case 0x1f4f:
|
|
case 0x1f58:
|
|
case 0x1f5a:
|
|
case 0x1f5c:
|
|
case 0x1f5e: return uc;
|
|
}
|
|
|
|
return uc ^ 0x08;
|
|
}
|
|
|
|
switch (uc) { default: break;
|
|
|
|
case 0x1fba:
|
|
case 0x1fbb: return uc - 0x4a;
|
|
|
|
case 0x1fc8:
|
|
case 0x1fc9:
|
|
case 0x1fca:
|
|
case 0x1fcb: return uc - 0x56;
|
|
|
|
case 0x1fda:
|
|
case 0x1fdb: return uc - 0x64;
|
|
|
|
case 0x1fea:
|
|
case 0x1feb: uc ^= 0x10;
|
|
case 0x1ff8:
|
|
case 0x1ff9: return uc ^ 0x80;
|
|
|
|
case 0x1fb8:
|
|
case 0x1fb9:
|
|
case 0x1fe8:
|
|
case 0x1fe9:
|
|
case 0x1fd8:
|
|
case 0x1fd9: return uc ^ 0x08;
|
|
|
|
case 0x1ffa:
|
|
case 0x1ffb: return uc - 0x7e;
|
|
|
|
case 0x1fec: uc += 2;
|
|
case 0x1fcc:
|
|
case 0x1ffc: return uc - 0x09;
|
|
}
|
|
#endif
|
|
|
|
return uc;
|
|
}
|
|
|
|
static unsigned int tolower_exclusions(unsigned int uc) {
|
|
|
|
switch (uc) { default: break;
|
|
case 0x04c0: return 0x04cf;
|
|
|
|
case 0x1cbd: return 0x10fd;
|
|
case 0x1cbe: return 0x10fe;
|
|
case 0x1cbf: return 0x10ff;
|
|
#ifndef COPTIC_DISABLE
|
|
case 0x2cf2:
|
|
case 0x2ceb:
|
|
case 0x2ced: 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 >= 0xa640 && uc <= 0xa66d && !(uc&1)) { // Cyrillic Extended-B
|
|
return uc + 1;
|
|
}
|
|
|
|
if (uc >= 0xa680 && uc <= 0xa69b && !(uc&1)) { // Cyrillic Extended-B
|
|
return uc + 1;
|
|
}
|
|
#endif
|
|
|
|
if (uc >= 0x0531 && uc <= 0x0556) { // Armenian
|
|
return uc + 0x30;
|
|
}
|
|
|
|
if ((uc >= 0x10a0 && uc <= 0x10c5) || uc == 0x10c7 || uc == 0x10cd) { // Georgian
|
|
return uc + 0x1c60;
|
|
}
|
|
|
|
if (uc >= 0x1c90 && uc <= 0x1cba) { // Georgian Extended
|
|
return uc - 0x0bc0;
|
|
}
|
|
#ifndef CHEROKEE_DISABLE
|
|
if (uc >= 0x13a0 && uc <= 0x13ef) { // Cherokee
|
|
return uc + 0x97d0;
|
|
}
|
|
if (uc >= 0x13f0 && uc <= 0x13f5) { // Cherokee
|
|
return uc | 0x08;
|
|
}
|
|
#endif
|
|
#ifndef GLAGOLITIC_DISABLE
|
|
if (uc >= 0x2c00 && uc <= 0x2c2e) { // Glagolitic
|
|
return uc + 0x30;
|
|
}
|
|
#endif
|
|
#ifndef COPTIC_DISABLE
|
|
if (uc >= 0x2c80 && uc <= 0x2ce3 && !(uc&1)) { // Coptic
|
|
return uc + 1;
|
|
}
|
|
#endif
|
|
#ifndef DESERET_DISABLE
|
|
if (uc >= 0x10400 && uc <= 0x10427) { // Deseret
|
|
return uc + 0x28;
|
|
}
|
|
#endif
|
|
#ifndef OSAGE_DISABLE
|
|
if (uc >= 0x104b0 && uc <= 0x104d3) { // Osage
|
|
return uc + 0x28;
|
|
}
|
|
#endif
|
|
#ifndef OLD_HUNGARIAN_DISABLE
|
|
if (uc >= 0x10c80 && uc <= 0x10cb2) { // Old Hungarian
|
|
return uc | 0x40;
|
|
}
|
|
#endif
|
|
#ifndef WARANG_CITI_DISABLE
|
|
if (uc >= 0x118a0 && uc <= 0x118bf) { // Warang Citi
|
|
return uc | 0x60;
|
|
}
|
|
#endif
|
|
|
|
return uc;
|
|
}
|
|
|
|
unsigned int tolower_unicode(unsigned int uc) {
|
|
|
|
if (uc >= 0x41 && uc <= 0x5a || (uc >= 0xc0 && uc <= 0xde && uc != 0xd7)) {
|
|
return uc | 0x20;
|
|
}
|
|
|
|
if (uc >= 0x0410 && uc <= 0x042f) { // Cyrillic
|
|
return uc + 0x20;
|
|
}
|
|
|
|
if (uc >= 0x0400 && uc <= 0x040f) { // Cyrillic
|
|
return uc + 0x50;
|
|
}
|
|
|
|
if (uc >= 0x0370 && uc <= 0x03ff) return tolower_greek_and_coptic(uc);
|
|
if (uc >= 0x1f00 && uc <= 0x1fff) return tolower_greek_extended(uc);
|
|
|
|
if (uc >= 0x0100 && uc <= 0x017f) return tolower_latin_extended_a(uc);
|
|
if (uc >= 0x0180 && uc <= 0x024f) return tolower_latin_extended_b(uc);
|
|
if (uc >= 0x2c60 && uc <= 0x2c7f) return tolower_latin_extended_c(uc);
|
|
if (uc >= 0xa720 && uc <= 0xa7ff) return tolower_latin_extended_d(uc);
|
|
if (uc >= 0x1e00 && uc <= 0x1eff) return tolower_latin_extended_additional(uc);
|
|
|
|
return tolower_exclusions(uc);
|
|
}
|