In the Spidermonkey 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.
Asked
Active
Viewed 627 times
2

mattbasta
- 13,492
- 9
- 47
- 68
1 Answers
1
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/

mattbasta
- 13,492
- 9
- 47
- 68
-
1This has changed. `read()` and `snarf()` are now always UTF-8. In fact there is no way to turn it off, so if you have a non-UTF-8 file this can be really annoying. :-P – Jason Orendorff Apr 25 '12 at 16:45