зеркало из https://github.com/mozilla/gecko-dev.git
114 строки
4.6 KiB
HTML
Executable File
114 строки
4.6 KiB
HTML
Executable File
<html>
|
|
<head>
|
|
<title>Test nsIConverterInputStream with UTF-16</title>
|
|
<meta http-equiv="content-type"; content="text/html; charset=utf-8">
|
|
<script type="text/javascript">
|
|
const beBOM="%FE%FF";
|
|
const leBOM="%FF%FE";
|
|
const sampleUTF16BE="%00%22%04%12%04A%045%00%20%04A%04G%040%04A%04B%04%3B%048%042%04K%045%00%20%04A%045%04%3C%04L%048%00%20%04%3F%04%3E%04E%04%3E%046%048%00%20%044%04%40%04C%043%00%20%04%3D%040%00%20%044%04%40%04C%043%040%00%2C%00%20%04%3A%040%046%044%040%04O%00%20%04%3D%045%04A%04G%040%04A%04B%04%3B%048%042%040%04O%00%20%04A%045%04%3C%04L%04O%00%20%04%3D%045%04A%04G%040%04A%04B%04%3B%048%042%040%00%20%04%3F%04%3E%00-%04A%042%04%3E%045%04%3C%04C%00.%00%22";
|
|
const sampleUTF16LE="%22%00%12%04A%045%04%20%00A%04G%040%04A%04B%04%3B%048%042%04K%045%04%20%00A%045%04%3C%04L%048%04%20%00%3F%04%3E%04E%04%3E%046%048%04%20%004%04%40%04C%043%04%20%00%3D%040%04%20%004%04%40%04C%043%040%04%2C%00%20%00%3A%040%046%044%040%04O%04%20%00%3D%045%04A%04G%040%04A%04B%04%3B%048%042%040%04O%04%20%00A%045%04%3C%04L%04O%04%20%00%3D%045%04A%04G%040%04A%04B%04%3B%048%042%040%04%20%00%3F%04%3E%04-%00A%042%04%3E%045%04%3C%04C%04.%00%22%00";
|
|
|
|
function makeText(withBOM, charset)
|
|
{
|
|
var theText = eval("sample" + charset);
|
|
if (withBOM) {
|
|
if (charset == "UTF16BE") {
|
|
theText = beBOM + theText;
|
|
} else {
|
|
theText = leBOM + theText;
|
|
}
|
|
}
|
|
return theText;
|
|
}
|
|
|
|
function testCase(withBOM, charset, charsetDec, decoder, bufferLength)
|
|
{
|
|
document.write("<tr><td>");
|
|
document.write(charset);
|
|
document.write("</td><td>");
|
|
if (withBOM)
|
|
document.write("with BOM");
|
|
else
|
|
document.write("without BOM");
|
|
document.write("</td><td>");
|
|
document.write(decoder);
|
|
document.write("</td><td>");
|
|
document.write(bufferLength);
|
|
document.write("<td>");
|
|
|
|
var dataURI = "data:text/plain;charset=" + charsetDec + "," +
|
|
makeText(withBOM, charset);
|
|
|
|
try {
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var channel = ioService.newChannel(dataURI, "", null);
|
|
var testInputStream = channel.open();
|
|
var testConverter =
|
|
Components.classes["@mozilla.org/intl/converter-input-stream;1"].
|
|
createInstance(Components.interfaces.nsIConverterInputStream);
|
|
testConverter.init(testInputStream, decoder, bufferLength,
|
|
Components.interfaces.nsIConverterInputStream.
|
|
DEFAULT_REPLACEMENT_CHARACTER);
|
|
|
|
if (!(testConverter instanceof
|
|
Components.interfaces.nsIUnicharLineInputStream))
|
|
throw "not line input stream";
|
|
|
|
var more;
|
|
do {
|
|
// read the line and check for eof
|
|
var line = {};
|
|
more = testConverter.readLine(line);
|
|
document.write(line.value);
|
|
} while (more)
|
|
} catch (e) {
|
|
document.write("Insufficient privileges!");
|
|
}
|
|
document.write("</td></tr>\n");
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<table border=1>
|
|
<tr>
|
|
<th colspan="2">Input file encoding</th>
|
|
<th>Decoder</th>
|
|
<th>Buffer length</th>
|
|
<th>Results</th>
|
|
<tr>
|
|
<th colspan="4">Reference rendering</td>
|
|
<td>"Все счастливые семьи похожи друг на друга, каждая несчастливая семья несчастлива по-своему."</td>
|
|
</tr>
|
|
<script type="text/javascript">
|
|
try {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
} catch(e) {
|
|
|
|
}
|
|
|
|
/* BOM charset charset decoder buffer
|
|
declaration length */
|
|
testCase(true, "UTF16LE", "UTF-16", "UTF-16", 64);
|
|
testCase(true, "UTF16BE", "UTF-16", "UTF-16", 64);
|
|
testCase(true, "UTF16LE", "UTF-16", "UTF-16LE", 64);
|
|
testCase(true, "UTF16BE", "UTF-16", "UTF-16BE", 64);
|
|
testCase(false, "UTF16LE", "UTF-16", "UTF-16", 64);
|
|
testCase(false, "UTF16BE", "UTF-16", "UTF-16", 64);
|
|
testCase(false, "UTF16LE", "UTF-16", "UTF-16LE", 64);
|
|
testCase(false, "UTF16BE", "UTF-16", "UTF-16BE", 64);
|
|
testCase(true, "UTF16LE", "UTF-16", "UTF-16", 65);
|
|
testCase(true, "UTF16BE", "UTF-16", "UTF-16", 65);
|
|
testCase(true, "UTF16LE", "UTF-16", "UTF-16LE", 65);
|
|
testCase(true, "UTF16BE", "UTF-16", "UTF-16BE", 65);
|
|
testCase(false, "UTF16LE", "UTF-16", "UTF-16", 65);
|
|
testCase(false, "UTF16BE", "UTF-16", "UTF-16", 65);
|
|
testCase(false, "UTF16LE", "UTF-16", "UTF-16LE", 65);
|
|
testCase(false, "UTF16BE", "UTF-16", "UTF-16BE", 65);
|
|
|
|
</script>
|
|
</table>
|
|
</body>
|
|
</html> |