read() in Spidermonkey with unicode
In the Spidermonke开发者_JS百科y shell, reading in a file with the read()
function ignores the encoding of the file. Is there any way to read in a UTF-8 or other multi-byte encoded file and preserve the multi-byte characters? Spidermonkey is such a little devil.
So I talked to the JS guys at Mozilla. Turns out this wasn't entirely possible, so they added a command line flag to enable UTF-8 support for read()
and snarf()
.
/usr/bin/js -e "print(read('filexyz.txt'))" -U
In order to get a copy of Spidermonkey with this addition, you'll have to use the Tracemonkey repository. You can get that with Mercurial:
hg clone http://hg.mozilla.org/tracemonkey/
精彩评论