[Project_owners] Open unicode files with jslib ?

Erwan Loisant erwanloisant at yahoo.co.jp
Sun Nov 9 17:45:00 EST 2003


Thank you for your answers.

Pete Collins wrote:

> I think that is because the javascript language uses the ASCII 
> character set.
>
Actually, to read a similar file but Japanese-English, I used code from 
an other GPL project 
(http://www.mozdev.org/source/browse/~checkout~/rikaixul/rikaixul/rikaixul/content/readfile.js?rev=1.3&content-type=text/plain).
Since data was encoded in the Japanese charset euc, and the code I 
borrowed did conversion to utf8 by using nsIScriptableUnicodeConverter, 
I assumed that reading an utf8 file from the disk would work 
out-of-the-box. It doesn't use jslib but user directly xpcom object.

After reading from this file, I can do anything with the strings I 
fetched, including displaying it in an "alert()", putting data in an 
iframe without characters to be broken.

> What hapends if you read the contents into a buffer and then write 
> them out to a file?

Interesting ; the resulting file (an utf8 text file) is OK. From all 
I've tried, this is the only operation that can return my unicode 
strings properly.

> How are you actually reading the file?
>
var f = new File(kanjidicPath);
f.open();
var kanjidicDatafr=new Array();
i=0;
while (!(f.EOF))
{
    kanjidicDatafr[i] = f.readline();
    i++;
}
alert(myArray[10])

The alert is just for testing, I also tried to  put it in an iframe 
since it will be my goal eventually. Not working, I just have strange 
accentuated western characters...

David Perry wrote:

> I had a similar problem with TagZilla.  After a lot of research, I 
> finally found something that seemed to do the trick in ChatZilla.  
> Based heavily on that, I made a mini-class that'll convert from disk 
> format to unicode and back again.  Check out

Interesting. I tried it, but since my string is unicode it ends up by 
utf8 to utf8, so has no effect. Do you use it to convert other encoding 
to/from utf8 ?

Well, I still have to try Karsten proposal !

-- 
Erwan Loisant - Ph.D. student
Tokyo Metro U. / Univ. Nantes
http://www.loisant.org




More information about the Project_owners mailing list