hex code point to char
by kuonyuu
JavaScript
var str = "\u9084\u6709\u9577\u8c37\u90e8\u7684 (\u5582";
alert(convertAllEscapes(str, 'hex'));
function convertAllEscapes (str, numbers) {
// converts all escapes in the text str to characters, and can interpret numbers as escapes too
// str: string, the text to be converted
// numbers: string enum [none, hex, dec, utf8, utf16], what to treat numbers as
sle = false;
str = convertUnicode2Char(str); //alert(str);
str = convertZeroX2Char(str); //alert(str);
str = convertHexNCR2Char(str); //alert(str);
str = convertDecNCR2Char(str); //alert(str);
if (sle) { str = convertjEsc2Char(str, true); }
else { str = convertjEsc2Char(str, false); //alert(str);
str = convertCSS2Char(str, false); } //alert(str);
str = convertpEnc2Char(str); //alert(str);
str = convertEntities2Char(str); //alert(str);
str = convertNumbers2Char(str, numbers); //alert(str);
return str;
}
function convertUnicode2Char ( str ) {
// converts a string containing U+... escapes to a string of characters
// str: string, the input
// first convert the 6 digit escapes to characters
str = str.replace(/[Uu]\+10([A-Fa-f0-9]{4})/g,
function(matchstr, parens) {
return hex2char('10'+parens);
}
);
// next convert up to 5 digit escapes to characters
str = str.replace(/[Uu]\+([A-Fa-f0-9]{1,5})/g,
function(matchstr, parens) {
return hex2char(parens);
}
);
return str;
}
function oldconvertUnicode2Char ( str ) {
// converts a string containing U+... escapes to a string of characters
// str: string, the input
// first convert the 6 digit escapes to characters
str = str.replace(/U\+10([A-Fa-f0-9]{4})/g,
function(matchstr, parens) {
return hex2char('10'+parens);
}
);
// next convert up to 5 digit escapes to characters
str = str.replace(/U\+([A-Fa-f0-9]{1,5})/g,
function(matchstr, parens) {
return hex2char(parens);
}
);
return str;
}
function convertHexNCR2Char ( str ) {...