Darin Fisher wrote:
Marek Lewczuk wrote:
var inputStream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream);
inputStream.setData(this.text, -1);
It sounds like you should be using nsIBinaryOutputStream instead. Try this code:
Wouldn't it be better to change nsIStringInputStream::setData to be sorta scriptable, say by making it take AUTF8String? (it is not frozen)
The problem really is that not everyone will be happy with UTF-8. We really need an interface that provides more options about how the string is encoded. Maybe a function like,
void setDataUnicode(in AString str, in unsigned long encodeAs)
would be good, with an option to express how that data is written to the stream. Here are some of the variations that come to mind:
enum {
ENCODE_ASCII,
ENCODE_FILESYSTEM,
ENCODE_UTF_8,
ENCODE_UTF_16,
ENCODE_UTF_16_BOM,
ENCODE_UTF_16_BE,
ENCODE_UTF_16_LE,
ENCODE_UTF_32,
ENCODE_UTF_32_BOM,
ENCODE_UTF_32_BE,
ENCODE_UTF_32_LE
};ENCODE_ASCII truncates unicode to 7-bit ASCII
ENCODE_FILESYSTEM
uses NS_CopyUnicodeToNative to convert unicode to the multibyte character encoding in use by the platform filesystem (based on value of LC_CTYPE on Unix, for example).
ENCODE_UTF_8 uses CopyUTF16toUTF8
ENCODE_UTF_16
copies input directly to the stream (i.e., UTF-16 in the host endianness w/o any byte order mark)
ENCODE_UTF_16_BOM copies input directly to the stream prefixed with a byte order mark
ENCODE_UTF_16_BE converts input to big endian if needed, and writes it to the stream
ENCODE_UTF_16_LE converts input to little endian if needed, and writes it to the stream
ENCODE_UTF_32 ENCODE_UTF_32_BOM ENCODE_UTF_32_BE ENCODE_UTF_32_LE like UTF-16 cases, but for UTF-32 instead. maybe we don't need these.
maybe we only need to start out with ENCODE_ASCII and ENCODE_UTF_8.
we might also want a flag to indicate whether or not to write a trailing null character.
-darin _______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom
