[bmx] Extended Lower$() and Upper$() by Space Fractal [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : Extended Lower$() and Upper$()
Author : Space Fractal
Posted : 1+ years ago

Description : The default Lower and Upper functions is very primitive and only suppert english latin characters and not various extended latin characters used by some languages.

This code got some help from Pure Basic to creating the s$ variable which can been found in this post:

<a href="http://www.blitzmax.com/Community/posts.php?topic=85260" target="_blank">http://www.blitzmax.com/Community/posts.php?topic=85260</a>

Feel free to use in any projects.

PS. Updated a little bit and renamed lower$ and upper$ functions, so they override better if you want a replace or use both.


Code :
Code (blitzmax) Select
Type TCase
Global L:String[]=New String[65536]
Global U:String[]=New String[65536]

Function init()
'generated from a Pure Basic app using Windows CharUpper_ unicode convertning
Local s$
s$="97=65;98=66;99=67;100=68;101=69;102=70;103=71;104=72;105=73;106=74;"
s$=s$+"107=75;108=76;109=77;110=78;111=79;112=80;113=81;114=82;115=83;116=84;"
s$=s$+"117=85;118=86;119=87;120=88;121=89;122=90;224=192;225=193;226=194;227=195;"
s$=s$+"228=196;229=197;230=198;231=199;232=200;233=201;234=202;235=203;236=204;237=205;"
s$=s$+"238=206;239=207;240=208;241=209;242=210;243=211;244=212;245=213;246=214;248=216;"
s$=s$+"249=217;250=218;251=219;252=220;253=221;254=222;255=376;257=256;259=258;261=260;"
s$=s$+"263=262;265=264;267=266;269=268;271=270;273=272;275=274;277=276;279=278;281=280;"
s$=s$+"283=282;285=284;287=286;289=288;291=290;293=292;295=294;297=296;299=298;301=300;"
s$=s$+"303=302;307=306;309=308;311=310;314=313;316=315;318=317;320=319;322=321;324=323;"
s$=s$+"326=325;328=327;331=330;333=332;335=334;337=336;339=338;341=340;343=342;345=344;"
s$=s$+"347=346;349=348;351=350;353=352;355=354;357=356;359=358;361=360;363=362;365=364;"
s$=s$+"367=366;369=368;371=370;373=372;375=374;378=377;380=379;382=381;384=579;387=386;"
s$=s$+"389=388;392=391;396=395;402=401;405=502;409=408;410=573;414=544;417=416;419=418;"
s$=s$+"421=420;424=423;429=428;432=431;436=435;438=437;441=440;445=444;447=503;454=452;"
s$=s$+"457=455;460=458;462=461;464=463;466=465;468=467;470=469;472=471;474=473;476=475;"
s$=s$+"477=398;479=478;481=480;483=482;485=484;487=486;489=488;491=490;493=492;495=494;"
s$=s$+"499=497;501=500;505=504;507=506;509=508;511=510;513=512;515=514;517=516;519=518;"
s$=s$+"521=520;523=522;525=524;527=526;529=528;531=530;533=532;535=534;537=536;539=538;"
s$=s$+"541=540;543=542;547=546;549=548;551=550;553=552;555=554;557=556;559=558;561=560;"
s$=s$+"563=562;570=11365;572=571;574=11366;578=577;583=582;585=584;587=586;589=588;591=590;"
s$=s$+"595=385;596=390;598=393;599=394;601=399;603=400;608=403;611=404;616=407;617=406;"
s$=s$+"619=11362;623=412;626=413;629=415;637=11364;640=422;643=425;648=430;649=580;650=433;"
s$=s$+"651=434;652=581;658=439;891=1021;892=1022;893=1023;940=902;941=904;942=905;943=906;"
s$=s$+"945=913;946=914;947=915;948=916;949=917;950=918;951=919;952=920;953=921;954=922;"
s$=s$+"955=923;956=924;957=925;958=926;959=927;960=928;961=929;962=931;963=931;964=932;"
s$=s$+"965=933;966=934;967=935;968=936;969=937;970=938;971=939;972=908;973=910;974=911;"
s$=s$+"985=984;987=986;989=988;991=990;993=992;995=994;997=996;999=998;1001=1000;1003=1002;"
s$=s$+"1005=1004;1007=1006;1010=1017;1016=1015;1019=1018;1072=1040;1073=1041;1074=1042;1075=1043;1076=1044;"
s$=s$+"1077=1045;1078=1046;1079=1047;1080=1048;1081=1049;1082=1050;1083=1051;1084=1052;1085=1053;1086=1054;"
s$=s$+"1087=1055;1088=1056;1089=1057;1090=1058;1091=1059;1092=1060;1093=1061;1094=1062;1095=1063;1096=1064;"
s$=s$+"1097=1065;1098=1066;1099=1067;1100=1068;1101=1069;1102=1070;1103=1071;1104=1024;1105=1025;1106=1026;"
s$=s$+"1107=1027;1108=1028;1109=1029;1110=1030;1111=1031;1112=1032;1113=1033;1114=1034;1115=1035;1116=1036;"
s$=s$+"1117=1037;1118=1038;1119=1039;1121=1120;1123=1122;1125=1124;1127=1126;1129=1128;1131=1130;1133=1132;"
s$=s$+"1135=1134;1137=1136;1139=1138;1141=1140;1143=1142;1145=1144;1147=1146;1149=1148;1151=1150;1153=1152;"
s$=s$+"1163=1162;1165=1164;1167=1166;1169=1168;1171=1170;1173=1172;1175=1174;1177=1176;1179=1178;1181=1180;"
s$=s$+"1183=1182;1185=1184;1187=1186;1189=1188;1191=1190;1193=1192;1195=1194;1197=1196;1199=1198;1201=1200;"
s$=s$+"1203=1202;1205=1204;1207=1206;1209=1208;1211=1210;1213=1212;1215=1214;1218=1217;1220=1219;1222=1221;"
s$=s$+"1224=1223;1226=1225;1228=1227;1230=1229;1231=1216;1233=1232;1235=1234;1237=1236;1239=1238;1241=1240;"
s$=s$+"1243=1242;1245=1244;1247=1246;1249=1248;1251=1250;1253=1252;1255=1254;1257=1256;1259=1258;1261=1260;"
s$=s$+"1263=1262;1265=1264;1267=1266;1269=1268;1271=1270;1273=1272;1275=1274;1277=1276;1279=1278;1281=1280;"
s$=s$+"1283=1282;1285=1284;1287=1286;1289=1288;1291=1290;1293=1292;1295=1294;1297=1296;1299=1298;1377=1329;"
s$=s$+"1378=1330;1379=1331;1380=1332;1381=1333;1382=1334;1383=1335;1384=1336;1385=1337;1386=1338;1387=1339;"
s$=s$+"1388=1340;1389=1341;1390=1342;1391=1343;1392=1344;1393=1345;1394=1346;1395=1347;1396=1348;1397=1349;"
s$=s$+"1398=1350;1399=1351;1400=1352;1401=1353;1402=1354;1403=1355;1404=1356;1405=1357;1406=1358;1407=1359;"
s$=s$+"1408=1360;1409=1361;1410=1362;1411=1363;1412=1364;1413=1365;1414=1366;7549=11363;7681=7680;7683=7682;"
s$=s$+"7685=7684;7687=7686;7689=7688;7691=7690;7693=7692;7695=7694;7697=7696;7699=7698;7701=7700;7703=7702;"
s$=s$+"7705=7704;7707=7706;7709=7708;7711=7710;7713=7712;7715=7714;7717=7716;7719=7718;7721=7720;7723=7722;"
s$=s$+"7725=7724;7727=7726;7729=7728;7731=7730;7733=7732;7735=7734;7737=7736;7739=7738;7741=7740;7743=7742;"
s$=s$+"7745=7744;7747=7746;7749=7748;7751=7750;7753=7752;7755=7754;7757=7756;7759=7758;7761=7760;7763=7762;"
s$=s$+"7765=7764;7767=7766;7769=7768;7771=7770;7773=7772;7775=7774;7777=7776;7779=7778;7781=7780;7783=7782;"
s$=s$+"7785=7784;7787=7786;7789=7788;7791=7790;7793=7792;7795=7794;7797=7796;7799=7798;7801=7800;7803=7802;"
s$=s$+"7805=7804;7807=7806;7809=7808;7811=7810;7813=7812;7815=7814;7817=7816;7819=7818;7821=7820;7823=7822;"
s$=s$+"7825=7824;7827=7826;7829=7828;7841=7840;7843=7842;7845=7844;7847=7846;7849=7848;7851=7850;7853=7852;"
s$=s$+"7855=7854;7857=7856;7859=7858;7861=7860;7863=7862;7865=7864;7867=7866;7869=7868;7871=7870;7873=7872;"
s$=s$+"7875=7874;7877=7876;7879=7878;7881=7880;7883=7882;7885=7884;7887=7886;7889=7888;7891=7890;7893=7892;"
s$=s$+"7895=7894;7897=7896;7899=7898;7901=7900;7903=7902;7905=7904;7907=7906;7909=7908;7911=7910;7913=7912;"
s$=s$+"7915=7914;7917=7916;7919=7918;7921=7920;7923=7922;7925=7924;7927=7926;7929=7928;7936=7944;7937=7945;"
s$=s$+"7938=7946;7939=7947;7940=7948;7941=7949;7942=7950;7943=7951;7952=7960;7953=7961;7954=7962;7955=7963;"
s$=s$+"7956=7964;7957=7965;7968=7976;7969=7977;7970=7978;7971=7979;7972=7980;7973=7981;7974=7982;7975=7983;"
s$=s$+"7984=7992;7985=7993;7986=7994;7987=7995;7988=7996;7989=7997;7990=7998;7991=7999;8000=8008;8001=8009;"
s$=s$+"8002=8010;8003=8011;8004=8012;8005=8013;8017=8025;8019=8027;8021=8029;8023=8031;8032=8040;8033=8041;"
s$=s$+"8034=8042;8035=8043;8036=8044;8037=8045;8038=8046;8039=8047;8048=8122;8049=8123;8050=8136;8051=8137;"
s$=s$+"8052=8138;8053=8139;8054=8154;8055=8155;8056=8184;8057=8185;8058=8170;8059=8171;8060=8186;8061=8187;"
s$=s$+"8064=8072;8065=8073;8066=8074;8067=8075;8068=8076;8069=8077;8070=8078;8071=8079;8080=8088;8081=8089;"
s$=s$+"8082=8090;8083=8091;8084=8092;8085=8093;8086=8094;8087=8095;8096=8104;8097=8105;8098=8106;8099=8107;"
s$=s$+"8100=8108;8101=8109;8102=8110;8103=8111;8112=8120;8113=8121;8115=8124;8140=8131;8144=8152;8145=8153;"
s$=s$+"8160=8168;8161=8169;8165=8172;8188=8179;8526=8498;8560=8544;8561=8545;8562=8546;8563=8547;8564=8548;"
s$=s$+"8565=8549;8566=8550;8567=8551;8568=8552;8569=8553;8570=8554;8571=8555;8572=8556;8573=8557;8574=8558;"
s$=s$+"8575=8559;8580=8579;9424=9398;9425=9399;9426=9400;9427=9401;9428=9402;9429=9403;9430=9404;9431=9405;"
s$=s$+"9432=9406;9433=9407;9434=9408;9435=9409;9436=9410;9437=9411;9438=9412;9439=9413;9440=9414;9441=9415;"
s$=s$+"9442=9416;9443=9417;9444=9418;9445=9419;9446=9420;9447=9421;9448=9422;9449=9423;11312=11264;11313=11265;"
s$=s$+"11314=11266;11315=11267;11316=11268;11317=11269;11318=11270;11319=11271;11320=11272;11321=11273;11322=11274;11323=11275;"
s$=s$+"11324=11276;11325=11277;11326=11278;11327=11279;11328=11280;11329=11281;11330=11282;11331=11283;11332=11284;11333=11285;"
s$=s$+"11334=11286;11335=11287;11336=11288;11337=11289;11338=11290;11339=11291;11340=11292;11341=11293;11342=11294;11343=11295;"
s$=s$+"11344=11296;11345=11297;11346=11298;11347=11299;11348=11300;11349=11301;11350=11302;11351=11303;11352=11304;11353=11305;"
s$=s$+"11354=11306;11355=11307;11356=11308;11357=11309;11358=11310;11361=11360;11368=11367;11370=11369;11372=11371;11382=11381;"
s$=s$+"11393=11392;11395=11394;11397=11396;11399=11398;11401=11400;11403=11402;11405=11404;11407=11406;11409=11408;11411=11410;"
s$=s$+"11413=11412;11415=11414;11417=11416;11419=11418;11421=11420;11423=11422;11425=11424;11427=11426;11429=11428;11431=11430;"
s$=s$+"11433=11432;11435=11434;11437=11436;11439=11438;11441=11440;11443=11442;11445=11444;11447=11446;11449=11448;11451=11450;"
s$=s$+"11453=11452;11455=11454;11457=11456;11459=11458;11461=11460;11463=11462;11465=11464;11467=11466;11469=11468;11471=11470;"
s$=s$+"11473=11472;11475=11474;11477=11476;11479=11478;11481=11480;11483=11482;11485=11484;11487=11486;11489=11488;11491=11490;"
s$=s$+"11520=4256;11521=4257;11522=4258;11523=4259;11524=4260;11525=4261;11526=4262;11527=4263;11528=4264;11529=4265;"
s$=s$+"11530=4266;11531=4267;11532=4268;11533=4269;11534=4270;11535=4271;11536=4272;11537=4273;11538=4274;11539=4275;"
s$=s$+"11540=4276;11541=4277;11542=4278;11543=4279;11544=4280;11545=4281;11546=4282;11547=4283;11548=4284;11549=4285;"
s$=s$+"11550=4286;11551=4287;11552=4288;11553=4289;11554=4290;11555=4291;11556=4292;11557=4293;65345=65313;65346=65314;"
s$=s$+"65347=65315;65348=65316;65349=65317;65350=65318;65351=65319;65352=65320;65353=65321;65354=65322;65355=65323;65356=65324;"
s$=s$+"65357=65325;65358=65326;65359=65327;65360=65328;65361=65329;65362=65330;65363=65331;65364=65332;65365=65333;65366=65334;"
s$=s$+"65367=65335;65368=65336;65369=65337;65370=65338;"
Local t$[] = s.split(";")

For Local i=0 To 65535
L[i]=Chr(i)
U[i]=Chr(i)
Next

For Local i=0 To Len(t$)-1
Local r$[]=t$[i].split("=")
If Len(r$)=2
Local uc=r$[1].toint()
Local lc=r$[0].toint()
L[uc]=Chr(lc)
U[lc]=Chr(uc)
EndIf
Next
EndFunction

Function LCase$(txt$)
Local result$=""
For Local i=1 To Len(txt$)
Local c=Asc(Mid(txt$, i, 1))
result$=result$+l[c]
Next
Return Trim$(result$)
EndFunction

Function UCase$(txt$)
Local result$=""
For Local i=1 To Len(txt$)
Local c=Asc(Mid(txt$, i, 1))
result$=result$+u[c]
Next
Return Trim(result$)
EndFunction
EndType


Comments : none...