当我使用 iconv 从 UTF16 转换为 UTF8 时,一切都很好,但反之亦然,它不起作用。
我有这些文件:
a-16.strings: Little-endian UTF-16 Unicode c program text
a-8.strings: UTF-8 Unicode c program text, with very long lines
文本在编辑器中看起来不错。当我运行这个时:
iconv -f UTF-8 -t UTF-16LE a-8.strings > b-16.strings
然后我得到这个结果:
b-16.strings: data
a-16.strings: Little-endian UTF-16 Unicode c program text
a-8.strings: UTF-8 Unicode c program text, with very long lines
The file
实用程序不显示预期的文件格式,并且文本在编辑器中看起来也不太好。是不是 iconv 没有创建正确的 BOM?我在 MAC 命令行上运行它。
为什么 b-16 不是正确的 UTF-16LE 格式?有没有其他方法将 utf8 转换为 utf16?
更多详细说明如下。
$ iconv -f UTF-8 -t UTF-16LE a-8.strings > b-16le-BAD-fromUTF8.strings
$ iconv -f UTF-8 -t UTF-16 a-8.strings > b-16be.strings
$ iconv -f UTF-16 -t UTF-16LE b-16be.strings > b-16le-BAD-fromUTF16BE.strings
$ file *s
a-16.strings: Little-endian UTF-16 Unicode c program text, with very long lines
a-8.strings: UTF-8 Unicode c program text, with very long lines
b-16be.strings: Big-endian UTF-16 Unicode c program text, with very long lines
b-16le-BAD-fromUTF16BE.strings: data
b-16le-BAD-fromUTF8.strings: data
$ od -c a-16.strings | head
0000000 377 376 / \0 * \0 \0 \f 001 E \0 S \0 K \0
$ od -c a-8.strings | head
0000000 / * * * Č ** E S K Y ( J V O
$ od -c b-16be.strings | head
0000000 376 377 \0 / \0 * \0 * \0 * \0 001 \f \0 E
$ od -c b-16le-BAD-fromUTF16BE.strings | head
0000000 / \0 * \0 * \0 * \0 \0 \f 001 E \0 S \0
$ od -c b-16le-BAD-fromUTF8.strings | head
0000000 / \0 * \0 * \0 * \0 \0 \f 001 E \0 S \0
很明显,每当我运行到 UTF-16LE 的转换时,BOM 就会丢失。
对此有什么帮助吗?