oxjstmp/tools/unicode2/unicode.js

38 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2010-01-07 20:21:07 +00:00
getNames();
function getNames() {
var //url = "http://unicode.org/Public/UNIDATA/NamesList.txt",
url = "NamesList.txt";
$.get(url, function(data) {
data = data.replace(/<control>\n\t=/g, "<control>");
var names = {}, json = "", split = [];
$.each(data.replace(/\n/g, "\n\n").match(/\n[0-9A-F]{4}\t.+\n/g), function(i, v) {
names["0x" + v.substr(1, 4)] = v.substr(6, v.length - 7);
});
json = JSON.stringify(names, null, 4)
$.each(data.match(/\n@@\t[0-9A-F]{4}\t.+\n/g), function(i, v) {
split = v.split("\t");
split[1] = "0x" + split[1];
xx = 0
while (split[1] in names == false && xx < 10) {
console.log(split[2],split[1])
split[1] = inc(split[1]);
xx++;
}
json = json.replace("\"" + split[1], "// " + split[2] + "\n \"" + split[1])
});
json = json
.replace(/ /g, "&nbsp;&nbsp;&nbsp;&nbsp;")
.replace(/\"0x/g, "0x")
.replace(/\":/g, ":")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\n/g, "<br/>");
$("body").html(json);
});
}
function inc(str) {
str = (parseInt(str, 16) + 1).toString(16).toUpperCase();
return "0x" + new Array(5 - str.length).join("0") + str;
}