summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/encoding/resources/char-decoding-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'LayoutTests/fast/encoding/resources/char-decoding-utils.js')
-rw-r--r--LayoutTests/fast/encoding/resources/char-decoding-utils.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/LayoutTests/fast/encoding/resources/char-decoding-utils.js b/LayoutTests/fast/encoding/resources/char-decoding-utils.js
new file mode 100644
index 0000000..a091ad8
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/char-decoding-utils.js
@@ -0,0 +1,34 @@
+function hex(number)
+{
+ var hexDigit = "0123456789ABCDEF";
+ var hex = hexDigit.substr(number & 0xf, 1);
+ while (number > 15) {
+ number >>= 4;
+ hex = hexDigit.substr(number & 15, 1) + hex;
+ }
+ return hex;
+}
+
+function decode(charsetName, characterSequence)
+{
+ var req = new XMLHttpRequest;
+ req.open('GET', 'data:text/plain,' + characterSequence, false);
+ req.overrideMimeType('text/plain; charset="' + charsetName + '"');
+ req.send('');
+ var code = hex(req.responseText.charCodeAt(0));
+ return "U+" + ("0000" + code).substr(code.length, 4);
+}
+
+function testDecode(charsetName, characterSequence, unicode)
+{
+ shouldBe("decode('" + charsetName + "', '" + characterSequence + "')", "'" + unicode + "'");
+}
+
+function batchTestDecode(inputData)
+{
+ for (var i in inputData.encodings) {
+ for (var j in inputData.encoded)
+ testDecode(inputData.encodings[i], inputData.encoded[j], inputData.unicode[j]);
+ }
+}
+