HighDots Forums  

jscript + charCodeAt, how to set js encoding?

Javascript JavaScript language (comp.lang.javascript)


Discuss jscript + charCodeAt, how to set js encoding? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: jscript + charCodeAt, how to set js encoding? - 02-03-2008 , 01:01 PM






VK wrote:
Quote:
On Feb 3, 8:16 pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de
wrote:
VK wrote:
Javascript operates only and exclusively with Unicode (note UTF-8) but
Unicode itself.
That is incoherent gibberish, and qualifies as nonsense.
Oh com'on, these are really ground basics.
*These* are not, because what you said is nonsense at best.

What exactly you did not understand in my explanations?
There is nothing to be understood where there is no meaning.
Someone should force you to read the nonsense that you post.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16


Reply With Quote
  #12  
Old   
Joost Diepenmaat
 
Posts: n/a

Default Re: jscript + charCodeAt, how to set js encoding? - 02-03-2008 , 01:15 PM






czechboy <oldrich.svec (AT) gmail (DOT) com> writes:

Quote:
To explain it in more detail. There is a javascript SDK plug-in in
FARR ( http://www.donationcoder.com/Forums/...?topic=11804.0
). It uses Microsoft scripting host to interpret javascript. I would
like to display unicode result (russian, greek etc) as RTF1 which
means that I have to convert ěščřž etc. to its decimal interpretation
by charCodeAt. So when I call the charCodeAt for the letter "č" the
SDK displays 356 but it should be 269.
I would expect MS jscript to do something as basic as charcodeat
correctly. My implementation (firefox) correctly gives 268 (0x10c) for
"Č". In any case it's more likely that the text is wrongly converted
somewhere before it reaches the script (i.e. converted from an encoding
that it's not in fact in).

Quote:
Do you think there might be an
error in the javascript SDK plug-in?
Could be. From your URL it appears that the host isn't unicode
aware.

Quote:
And concerning the function. It is what I have found on the internet.
I an javascript newbie
Don't use it. it's incorrect.

Joost.


Reply With Quote
  #13  
Old   
czechboy
 
Posts: n/a

Default Re: jscript + charCodeAt, how to set js encoding? - 02-04-2008 , 03:04 AM



On 3 n, 19:15, Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> wrote:
Quote:
czechboy <oldrich.s... (AT) gmail (DOT) com> writes:
To explain it in more detail. There is a javascript SDK plug-in in
FARR (http://www.donationcoder.com/Forums/...?topic=11804.0
). It uses Microsoft scripting host to interpret javascript. I would
like to display unicode result (russian, greek etc) as RTF1 which
means that I have to convert etc. to its decimal interpretation
by charCodeAt. So when I call the charCodeAt for the letter "" the
SDK displays 356 but it should be 269.

I would expect MS jscript to do something as basic as charcodeat
correctly. My implementation (firefox) correctly gives 268 (0x10c) for
"". In any case it's more likely that the text is wrongly converted
somewhere before it reaches the script (i.e. converted from an encoding
that it's not in fact in).

Do you think there might be an
error in the javascript SDK plug-in?

Could be. From your URL it appears that the host isn't unicode
aware.

And concerning the function. It is what I have found on the internet.
I an javascript newbie

Don't use it. it's incorrect.

Joost.
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


Reply With Quote
  #14  
Old   
Bart Van der Donck
 
Posts: n/a

Default Re: jscript + charCodeAt, how to set js encoding? - 02-04-2008 , 04:03 AM



Joost Diepenmaat wrote:

Quote:
charCodeAt already returns the unicode codepoint and strings in
javascript are unicode. The conversion to and from other encodings is
presumably handled by the scripting host (i.e. the browser).
Yes, and more specifically, by the character set of the web page.

<textarea></textarea>

returns under

Western European, charset=iso-8859-1: 233 and 232
Central European, charset=iso-8859-2: 233 and 269
Eastern European, charset=iso-8859-5: 1097 and 1096
Russian, charset=KOI8-R: 1048 and 1061

But the real fun starts with multibyte-sequences (saved under ANSI,
not UTF-8):

Japanese, charset=shift-jis: 40167 (one character)
Trad. Chinese, charset=big5: 27654 (one character)

--
Bart


Reply With Quote
  #15  
Old   
Joost Diepenmaat
 
Posts: n/a

Default Re: jscript + charCodeAt, how to set js encoding? - 02-04-2008 , 05:16 AM



czechboy <oldrich.svec (AT) gmail (DOT) com> writes:
Quote:
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.


Reply With Quote
  #16  
Old   
czechboy
 
Posts: n/a

Default Re: jscript + charCodeAt, how to set js encoding? - 02-04-2008 , 10:18 AM



On 4 n, 11:16, Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> wrote:
Quote:
czechboy <oldrich.s... (AT) gmail (DOT) com> writes:
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));
};

})();


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.