C++ utf8 mb_strtoupper function
#include <iostream>
#include <string>
using namespace std;
string mb_strtoupper(string m);
int main(int argc, char *argv[])
{
cout << mb_strtoupper("québec") << endl;
cout << mb_strtoupper("πρστυφχψωϊϋ") << endl;
return 0;
}
string mb_strtoupper(string m)
{
string out;
int j=0,k=0;
for(int i=0, ix=m.length(); i<ix; i+=1, j++)
{
unsigned char c0=m[i];
if (c0>=0 && c0<=127)
{
if ('a'<=c0 && c0<='z') { c0-=0x20; }
out+= c0;
}
else if (c0>=192 && c0<=223)
{
unsigned char c1=m[i+1];
if (c0==0xc4 && c1==0xb1) { out+=0x49; }
else if (c0==0xc5 && c1==0xbf) { out+=0x53; }
else if (c0==0xc2 && c1==0xb5) { out+=0xce; out+=0x9c; }
else if (c0==0xc3 && c1==0xbf) { out+=(c0+2); out+=0xb8; }
else if (c0==0xc5 && c1==0x80) { out+=(c0-1); out+=0xbf; }
else if (c0==0xd2 && c1==0x81) { out+=c0; out+=(c1-1); }
else if (c0==0xce && c1==0xac) { out+=c0; out+=(c1-0x26); }
else if (c0==0xcf && c1==0x8c) { out+=(c0-1); out+=c1; }
else if (c0==0xcf && c1==0x90) { out+=(c0-1); out+=(c1+2); }
else if (c0==0xcf && c1==0x82) { out+=(c0-1); out+=(c1+0x21); }
else if (c0==0xc9 && c1==0x93) { out+=(c0-3); out+=(c1-0x12); }
else if (c0==0xc9 && c1==0x94) { out+=(c0-3); out+=(c1-0x0e); }
else if (c0==0xc9 && c1==0x99) { out+=(c0-3); out+=(c1-0x0a); }
else if (c0==0xc9 && c1==0x9b) { out+=(c0-3); out+=(c1-0x0b); }
else if (c0==0xc9 && c1==0xa3) { out+=(c0-3); out+=(c1-0x0f); }
else if (c0==0xc9 && c1==0xa8) { out+=(c0-3); out+=(c1-0x11); }
else if (c0==0xc9 && c1==0xb2) { out+=(c0-3); out+=(c1-0x15); }
else if (c0==0xc9 && c1==0xb5) { out+=(c0-3); out+=(c1-0x16); }
else if (c0==0xca && c1==0x92) { out+=(c0-4); out+=(c1+0x25); }
else if (c0==0xcf && c1==0x91) { out+=(c0-1); out+=(c1+0x07); }
else if (c0==0xcf && c1==0x95) { out+=(c0-1); out+=(c1+0x11); }
else if (c0==0xcf && c1==0x96) { out+=(c0-1); out+=(c1+0x0a); }
else if (c0==0xcf && c1==0xb0) { out+=(c0-1); out+=(c1-0x16); }
else if (c0==0xcf && c1==0xb1) { out+=(c0-1); out+=(c1-0x10); }
else if (c0==0xcf && c1==0xb2) { out+=(c0-1); out+=(c1-0x0f); }
else if (c0==0xc7 && c1==0x9d) { out+=(c0-1); out+=(c1-0x0f); }
else if (c0==0xcf && c1==0xb5) { out+=(c0-1); out+=(c1-0x20); }
else if (c0==0xc6 && c1==0xbf) { out+=(c0+1); out+=(c1-0x08); }
else if (c0==0xc6 && c1==0x95) { out+=(c0+1); out+=(c1+0x21); }
else if (c0==0xc6 && c1==0x9e) { out+=(c0+2); out+=(c1+0x02); }
else if (c0==0xd5 && 0xb0<=c1 && c1 <=0xbf ) { out+=c0; out+=(c1-0x30); }
else if (c0==0xce && 0xad<=c1 && c1 <=0xaf ) { out+=c0; out+=(c1-0x25); }
else if (c0==0xce && 0xb1<=c1 && c1 <=0xbf ) { out+=c0; out+=(c1-0x20); }
else if (c0==0xd0 && 0xb0<=c1 && c1 <=0xbf ) { out+=c0; out+=(c1-0x20); }
else if (c0==0xd1 && 0x80<=c1 && c1 <=0x8f ) { out+=(c0-1); out+=(c1+0x20); }
else if (c0==0xd1 && 0x90<=c1 && c1 <=0x9f ) { out+=(c0-1); out+=(c1-0x10); }
else if (c0==0xd5 && 0xa1<=c1 && c1 <=0xaf ) { out+=(c0-1); out+=(c1+0x10); }
else if (c0==0xd6 && 0x80<=c1 && c1 <=0x86 ) { out+=(c0-1); out+=(c1+0x10); }
else if (c0==0xcf && 0x80<=c1 && c1 <=0x81 ) { out+=(c0-1); out+=(c1+0x20); }
else if (c0==0xcf && 0x83<=c1 && c1 <=0x8b ) { out+=(c0-1); out+=(c1+0x20); }
else if (c0==0xcf && 0x8d<=c1 && c1 <=0x8e ) { out+=(c0-1); out+=(c1+1); }
else if (c0==0xca && 0x8a<=c1 && c1 <=0x8b ) { out+=(c0-4); out+=(c1+0x27); }
else if (c0==0xc3 && 0xa0<=c1 && c1 <=0xbe && c1!=0xb7) { out+=c0; out+=c1-0x20; }
else if (c0==0xc4 && 0x81<=c1 && c1 <=0xaf && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc4 && 0xb3<=c1 && c1 <=0xb7 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc4 && 0xba<=c1 && c1 <=0xbe && c1%2==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc5 && 0x82<=c1 && c1 <=0x88 && c1%2==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc5 && 0x8b<=c1 && c1 <=0x8f && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc5 && 0x91<=c1 && c1 <=0xb7 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc5 && 0xba<=c1 && c1 <=0xbe && c1%2==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0x83<=c1 && c1 <=0x85 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0xa1<=c1 && c1 <=0xa5 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0x88<=c1 && c1 <=0x8c && c1%4==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0x92<=c1 && c1 <=0x99 && c1%7==6 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0xa8<=c1 && c1 <=0xad && c1%5==3 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0xb0<=c1 && c1 <=0xb4 && c1%4==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0xb6<=c1 && c1 <=0xb9 && c1%3==2 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc6 && 0xbc<=c1 && c1 <=0xbe && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc7 && 0x90<=c1 && c1 <=0x9c && c1%2==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc7 && 0x8c<=c1 && c1 <=0x8e && c1%2==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc7 && 0x86<=c1 && c1 <=0x89 && c1%3==2 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc7 && 0x9f<=c1 && c1 <=0xaf && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc7 && 0xb3<=c1 && c1 <=0xb5 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc7 && 0xb9<=c1 && c1 <=0xbf && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc8 && 0x81<=c1 && c1 <=0x9f && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc8 && 0xa3<=c1 && c1 <=0xb3 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xcf && 0x99<=c1 && c1 <=0xaf && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xd1 && 0xa1<=c1 && c1 <=0xbf && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xd2 && 0x8b<=c1 && c1 <=0xbf && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xd3 && 0x82<=c1 && c1 <=0x8e && c1%2==0 ) { out+=c0; out+=(c1-1); }
else if (c0==0xd3 && 0x91<=c1 && c1 <=0xb5 && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xd3 && 0xb8<=c1 && c1 <=0xba && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xd4 && 0x81<=c1 && c1 <=0x8f && c1%2==1 ) { out+=c0; out+=(c1-1); }
else if (c0==0xc9 && 0xa9<=c1 && c1 <=0xaf && c1%6==1 ) { out+=(c0-3); out+=(c1-0x13); }
else if (c0==0xca && (c1==0x80 || c1==0x83 || c1==0x88)) { out+=(c0-4); out+=(c1+0x26);}
else if (c0==0xc9 && (c1==0x96 || c1==0x97 || c1==0xa0)) { out+=(c0-3); out+=(c1-0x0d);}
else { out+=c0; out+=c1; }
}
else if (c0>=224 && c0<=239)
{
unsigned char c1=m[i+1];
unsigned char c2=m[i+2];
if (0){}
else if (c0==0xe1 && c1==0xbe && c2==0xbe ) { out+=0xce; out+=0x99; }
else if (c0==0xe1 && c1==0xba && c2==0x9b ) { out+=0xe1; out+=0xb9; out+=0xa0; }
else if (c0==0xe1 && c1==0xbf && c2==0x83 ) { out+=0xe1; out+=0xbf; out+=0x8c; }
else if (c0==0xe1 && c1==0xbf && c2==0xa5 ) { out+=0xe1; out+=0xbf; out+=0xac; }
else if (c0==0xe1 && c1==0xb8 && 0x81<=c2 && c2<=0xbf && c2%2==1) { out+=c0; out+=c1; out+=(c2-1); }
else if (c0==0xe1 && c1==0xb9 && 0x81<=c2 && c2<=0xbf && c2%2==1) { out+=c0; out+=c1; out+=(c2-1); }
else if (c0==0xe1 && c1==0xba && 0x81<=c2 && c2<=0x95 && c2%2==1) { out+=c0; out+=c1; out+=(c2-1); }
else if (c0==0xe1 && c1==0xba && 0xa1<=c2 && c2<=0xbf && c2%2==1) { out+=c0; out+=c1; out+=(c2-1); }
else if (c0==0xe1 && c1==0xbb && 0x81<=c2 && c2<=0xb9 && c2%2==1) { out+=c0; out+=c1; out+=(c2-1); }
else if (c0==0xe1 && c1==0xbd && 0x91<=c2 && c2<=0x97 && c2%2==1) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbc && 0x80<=c2 && c2<=0x87) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbc && 0x90<=c2 && c2<=0x95) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbc && 0xa0<=c2 && c2<=0xa7) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbc && 0xb0<=c2 && c2<=0xb7) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbd && 0x80<=c2 && c2<=0x85) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbd && 0xa0<=c2 && c2<=0xa7) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbe && 0x80<=c2 && c2<=0x87) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbe && 0x90<=c2 && c2<=0x97) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbe && 0xa0<=c2 && c2<=0xa7) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbe && 0xb0<=c2 && c2<=0xb1) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbf && 0x90<=c2 && c2<=0x91) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && c1==0xbf && 0xa0<=c2 && c2<=0xa1) { out+=c0; out+=c1; out+=(c2+0x08); }
else if (c0==0xe1 && 0xbe<=c1 && c1<=0xbf && c2==0xb3) { out+=c0; out+=c1; out+=(c2+0x09); }
else if (c0==0xe1 && c1==0xbd && 0xb8<=c2 && c2<=0xb9) { out+=c0; out+=(c1+2); out+=c2; }
else if (c0==0xe1 && c1==0xbd && 0xb0<=c2 && c2<=0xb1) { out+=c0; out+=(c1+1); out+=(c2+0x0a); }
else if (c0==0xe1 && c1==0xbd && 0xb2<=c2 && c2<=0xb5) { out+=c0; out+=(c1+2); out+=(c2-0x2a); }
else if (c0==0xe1 && c1==0xbd && 0xb6<=c2 && c2<=0xb7) { out+=c0; out+=(c1+2); out+=(c2-0x1c); }
else if (c0==0xe1 && c1==0xbd && 0xba<=c2 && c2<=0xbb) { out+=c0; out+=(c1+2); out+=(c2-0x10); }
else if (c0==0xe1 && c1==0xbd && 0xbc<=c2 && c2<=0xbd) { out+=c0; out+=(c1+2); out+=(c2-0x02); }
else { out+= c0; out+=c1; out+=c2; }
}
if (c0>=0 && c0<=127) { i+=0; }
else if (c0>=192 && c0<=223) { i+=1; }
else if (c0>=224 && c0<=239) { i+=2; }
else if (c0>=240 && c0<=247) { i+=3; }
}
return out;
}QUÉBEC ΠΡΣΤΥΦΧΨΩΪΫ
code snippets are licensed under Creative Commons CC-By-SA 3.0 (unless otherwise specified)
|