On 4 n, 11:16, Joost Diepenmaat <jo...@zeekat.nlwrote:
czechboy <oldrich.s...@gmail.comwrites:
Thank you for your help. Now it is working. Could you please post me
correct function? I am not that skilled to do one by myself ;) Thank
you
I think Thomas already posted a correction to the function in this
thread. Look it up.
Joost.
Thanks. Meanwhile I have found another function which seams to work
fine. Is it the correct function?
(function(){
var unicode = {
/**
*
*
*/
'dec2hex' : function(ts)
{
return (ts+0).toString(16).toUpperCase();
},
/**
*
*
*/
'dec2hex2' : function(ts)
{
var hexequiv = new Array ("0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "A", "B", "C", "D", "E", "F");
return hexequiv[(ts >4) & 0xF] + hexequiv[ts & 0xF];
},
/**
*
*
*/
'dec2hex4' : function(ts)
{
var hexequiv = new Array ("0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "A", "B", "C", "D", "E", "F");
return hexequiv[(ts >12) & 0xF] + hexequiv[(ts >8) & 0xF] +
hexequiv[(ts >4) & 0xF] + hexequiv[ts & 0xF];
},
/**
*
*
*/
'convertCP2Char' : function(ts)
{
var outputString = '';
ts = ts.replace(/^\s+/, '');
if(ts.length == 0)
return "";
ts = ts.replace(/\s+/g, ' ');
var listArray = ts.split(' ');
for(var i = 0; i < listArray.length; i++)
{
var n = parseInt(listArray[i], 16);
if(n <= 0xFFFF)
outputString += String.fromCharCode(n);
else if (n <= 0x10FFFF)
{
n -= 0x10000;
outputString += String.fromCharCode(0xD800 | (n >10)) +
String.fromCharCode(0xDC00 | (n & 0x3FF));
}
else
outputString += '!erreur ' + unicode.dec2hex(n) +'!';
}
return( outputString );
},
/**
*
*
*/
'convertCP2DecNCR' : function(ts)
{
var outputString = "";
ts = ts.replace(/^\s+/, '');
if(ts.length == 0)
return "";
ts = ts.replace(/\s+/g, ' ');
var listArray = ts.split(' ');
for(var i = 0; i < listArray.length; i++)
{
var n = parseInt(listArray[i], 16);
outputString += ('{\\u' + n + '}');
}
return(outputString);
},
/**
*
*
*/
'convertChar2CP' : function(ts)
{
var outputString = "", haut = 0, n = 0;
for(var i = 0; i < ts.length; i++)
{
var b = ts.charCodeAt(i);
if(b < 0 || b 0xFFFF)
outputString += '!erreur ' + unicode.dec2hex(b) + '!';
if(haut != 0)
{
if(0xDC00 <= b && b <= 0xDFFF)
{
outputString += unicode.dec2hex(0x10000 + ((haut - 0xD800) <<
10) + (b - 0xDC00)) + ' ';
haut = 0;
continue;
}
else
{
outputString += '!erreur ' + unicode.dec2hex(haut) + '!';
haut = 0;
}
}
if(0xD800 <= b && b <= 0xDBFF)
haut = b;
else
outputString += unicode.dec2hex(b) + ' ';
}
return( outputString.replace(/ $/, '') );
},
/**
*
*
*/
'convertDecNCR2CP' : function(ts)
{
var outputString = '';
ts = ts.replace(/\s/g, '');
var listArray = ts.split(';');
for (var i = 0; i < listArray.length-1; i++)
{
if(i 0)
outputString += ' ';
var n = parseInt(listArray[i].substring(2, listArray[i].length),
10);
outputString += unicode.dec2hex(n);
}
return( outputString );
}
};
/**
* Convert Character to Decimal.
*
* @example "JavaScript".char2dec();
* @result "JavaScript"
*
* @name char2dec
* @return String
*/
if(!String.prototype.char2dec)
String.prototype.char2dec = function()
{
return unicode.convertCP2DecNCR(unicode.convertChar2CP(th is));
};
/**
* Convert Decimal to Character.
*
* @example
"JavaScript".dec2char();
* @result "JavaScript"
*
* @name dec2char
* @return String
*/
if(!String.prototype.dec2char)
String.prototype.dec2char = function()
{
return unicode.convertCP2Char(unicode.convertDecNCR2CP(th is));
};
})();