Conversion de Unicode a Griego, segunda parte
Y es que la solución de ayer era lenta, muuuy lenta. Así que tras seguir los sabios consejos de un compañero, he pasado a hacer tantos replaces como caracteres haya que convertir, en lugar de comparar carácter a carácter.
Además, para mantener un código más limpio, he montado dos arrays, uno con los códigos Unicode, y otro con los códigos Griegos. Y he cambiado el prototipo por una denominada multiReplace que recibe los dos arrays como parámetros. Así podría usarse de nuevo con distintas tablas.
string.multireplace.as
#include "string.replace.as”
String.prototype.multiReplace = function(arr1,arr2) {
var tmpStr = this;
for(var i=0;i<arr1.length;i++)
tmpStr = tmpStr.replace(String.fromCharCode(arr1[i]),String.fromCharCode(arr2[i]));
return tmpStr;
}
unicodeToGreek.as
unicodeChars = Array(); greekChars = Array();
unicodeChars.push(0x0385); greekChars.push(0xA1);
unicodeChars.push(0x0386); greekChars.push(0xA2);
unicodeChars.push(0x0384); greekChars.push(0xB4);
unicodeChars.push(0x0388); greekChars.push(0xB8);
unicodeChars.push(0x0389); greekChars.push(0xB9);
unicodeChars.push(0x038A); greekChars.push(0xBA);
unicodeChars.push(0x038C); greekChars.push(0xBC);
unicodeChars.push(0x038E); greekChars.push(0xBE);
unicodeChars.push(0x038F); greekChars.push(0xBF);
unicodeChars.push(0x0390); greekChars.push(0xC0);
unicodeChars.push(0x0391); greekChars.push(0xC1);
unicodeChars.push(0x0392); greekChars.push(0xC2);
unicodeChars.push(0x0393); greekChars.push(0xC3);
unicodeChars.push(0x0394); greekChars.push(0xC4);
unicodeChars.push(0x0395); greekChars.push(0xC5);
unicodeChars.push(0x0396); greekChars.push(0xC6);
unicodeChars.push(0x0397); greekChars.push(0xC7);
unicodeChars.push(0x0398); greekChars.push(0xC8);
unicodeChars.push(0x0399); greekChars.push(0xC9);
unicodeChars.push(0x039A); greekChars.push(0xCA);
unicodeChars.push(0x039B); greekChars.push(0xCB);
unicodeChars.push(0x039C); greekChars.push(0xCC);
unicodeChars.push(0x039D); greekChars.push(0xCD);
unicodeChars.push(0x039E); greekChars.push(0xCE);
unicodeChars.push(0x039F); greekChars.push(0xCF);
unicodeChars.push(0x03A0); greekChars.push(0xD0);
unicodeChars.push(0x03A1); greekChars.push(0xD1);
unicodeChars.push(0x03A3); greekChars.push(0xD3);
unicodeChars.push(0x03A4); greekChars.push(0xD4);
unicodeChars.push(0x03A5); greekChars.push(0xD5);
unicodeChars.push(0x03A6); greekChars.push(0xD6);
unicodeChars.push(0x03A7); greekChars.push(0xD7);
unicodeChars.push(0x03A8); greekChars.push(0xD8);
unicodeChars.push(0x03A9); greekChars.push(0xD9);
unicodeChars.push(0x03AA); greekChars.push(0xDA);
unicodeChars.push(0x03AB); greekChars.push(0xDB);
unicodeChars.push(0x03AB); greekChars.push(0xDB);
unicodeChars.push(0x03AC); greekChars.push(0xDC);
unicodeChars.push(0x03AD); greekChars.push(0xDD);
unicodeChars.push(0x03AE); greekChars.push(0xDE);
unicodeChars.push(0x03AF); greekChars.push(0xDF);
unicodeChars.push(0x03B0); greekChars.push(0xE0);
unicodeChars.push(0x03B1); greekChars.push(0xE1);
unicodeChars.push(0x03B2); greekChars.push(0xE2);
unicodeChars.push(0x03B3); greekChars.push(0xE3);
unicodeChars.push(0x03B4); greekChars.push(0xE4);
unicodeChars.push(0x03B5); greekChars.push(0xE5);
unicodeChars.push(0x03B6); greekChars.push(0xE6);
unicodeChars.push(0x03B7); greekChars.push(0xE7);
unicodeChars.push(0x03B8); greekChars.push(0xE8);
unicodeChars.push(0x03B9); greekChars.push(0xE9);
unicodeChars.push(0x03BA); greekChars.push(0xEA);
unicodeChars.push(0x03BB); greekChars.push(0xEB);
unicodeChars.push(0x03BC); greekChars.push(0xEC);
unicodeChars.push(0x03BD); greekChars.push(0xED);
unicodeChars.push(0x03BE); greekChars.push(0xEE);
unicodeChars.push(0x03BF); greekChars.push(0xEF);
unicodeChars.push(0x03C0); greekChars.push(0xF0);
unicodeChars.push(0x03C1); greekChars.push(0xF1);
unicodeChars.push(0x03C2); greekChars.push(0xF2);
unicodeChars.push(0x03C3); greekChars.push(0xF3);
unicodeChars.push(0x03C4); greekChars.push(0xF4);
unicodeChars.push(0x03C5); greekChars.push(0xF5);
unicodeChars.push(0x03C6); greekChars.push(0xF6);
unicodeChars.push(0x03C7); greekChars.push(0xF7);
unicodeChars.push(0x03C8); greekChars.push(0xF8);
unicodeChars.push(0x03C9); greekChars.push(0xF9);
unicodeChars.push(0x03CA); greekChars.push(0xFA);
unicodeChars.push(0x03CB); greekChars.push(0xFB);
unicodeChars.push(0x03CC); greekChars.push(0xFC);
unicodeChars.push(0x03CD); greekChars.push(0xFD);
unicodeChars.push(0x03CE); greekChars.push(0xFE);
Modo de uso
#include "unicodeToGreek.as"
#include "string.multireplace.as"
text = text.multireplace(unicodeChars,greekChars);














