[Project_owners] Open unicode files with jslib ?

David Perry d.perry at utoronto.ca
Sun Nov 9 10:09:10 EST 2003

Erwan Loisant wrote:
> Forget what I said in the previous message. It works ! It is strange 
> that convert from unicode to unicode is necessary, however...

Well, that's not exactly what's happening.  (If you're not interested in 
why, skip the rest of this message (: )

As near as I can tell, when you read a file with JSLib, you're reading 
in the byte stream -- each character is represented by a value between 0 
and 255, like in the old DOS days.  So if you just use the read-in 
string as it is, you aren't using a UTF-8 string.

Why not?  Well, UTF-8 has to fit in 8 bytes, but it has way more than 
256 characters, so it uses special control sequences to help it 
represent the extra characters.  Maybe future versions of JSLib will do 
the conversion for us, but until then, we have to run it through 
nsIScriptableUnicodeConverter ourselves to convert between UTF-8 and 
disk format.

Please note that the byte stream is (essentially) identical for both 
formats.  What's changing when you use the converter is that you're 
telling JavaScript to read it as UTF-8 and not just as a stream of 
"old-fashioned" 8-bit characters.

> Thank you very much !

I'm glad it worked for you!  Like I said, Rob Ginda did the hard work. (:


More information about the Project_owners mailing list