A set of dependency-free basic internationalization tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
2.2 KiB

<!DOCTYPE html>
<meta charset=big5>
<!-- Correct results are provided by Firefox -->
<pre style="font-family: 'Consolas', monospace;"></pre>
<script>
"use strict";
/*
Char 0 U+007A (1 byte) Offset 0
Char 1 U+00A2 (2 bytes) Offset 1
Char 2 U+6C34 (3 bytes) Offset 3
Char 3 U+1D11E (4 bytes) Offset 6
Char 4 U+F8FF (3 bytes) Offset 10
Char 5 U+10FFFD (4 bytes) Offset 13
Char 6 U+FFFE (3 bytes) Offset 17
End of string at char 7, offset 20
*/
[0x7A, 0xA2, 0x6C34, 0x1D11E, 0xF8FF, 0x10FFFD, 0xFFFE].forEach(function(code) {
var l = document.createElement("a");
l.href = "http://example.com/?" + String.fromCodePoint(code);
var url = l.search.substr(1);
var bytes = [];
for (let a = 0; a < url.length; a++) {
if (url.charAt(a) == "%") {
bytes.push(url.charAt(a + 1) + url.charAt(a + 2));
a = a + 2;
} else {
bytes.push(url.charCodeAt(a).toString(16).padStart(2, "0"));
}
}
var line = bytes.join(" ").toUpperCase() + "\n";
document.getElementsByTagName("pre")[0].appendChild(document.createTextNode(line));
})
document.getElementsByTagName("pre")[0].appendChild(document.createTextNode("\n\n\n"));
var dec = new TextDecoder("big5");
for (let lead = 0x87; lead < 0xFF; lead++) {
for (let trail = 0x40; trail < 0xFF; trail++) {
if (trail == 0x7F) trail = 0xA1;
let bytes = [];
bytes.push(lead.toString(16).padStart(2, "0").toUpperCase());
bytes.push(trail.toString(16).padStart(2, "0").toUpperCase());
let codes = [];
let text = dec.decode(new Uint8Array([lead, trail]));
for (let a = 0; a < text.length; a++) {
let point = text.codePointAt(a);
if (point >= 55296 && point <= 57343) {
// non-BMP characters have trailing low surrogates in JavaScript strings
continue;
}
codes.push(point);
}
if (codes.length == 1) {
//continue;
}
bytes = bytes.join(" ");
codes = codes.join(", ");
var line = "[" + '"' + bytes + '", [' + codes + "]],\n";
document.getElementsByTagName("pre")[0].appendChild(document.createTextNode(line));
}
}
</script>