今天吃了荔枝 >>
<< 呜呜,我的mp3坏了!
Reversely Transform the messages_zh_CN.properties

Author Zhou Renjian Create@ 2005-06-03 17:25
whizz Note icon
<textarea id="source" cols="80" rows="25"></textarea>
<button onclick="transform();">Transform</button>
<button onclick="rtransform();">R-Transform</button>
<script type="text/javascript">

var digitArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function toHex(n){
    var result = ''
    var start = true;
    for (var i=32; i>0;){
        i-=4;
        var digit = (n>>i) & 0xf;
        if (!start || digit != 0){
            start = false;
            result += digitArray[digit];
        }
    }
    return (result==''?'0':result);
}
function transform() {
    var srcEl = document.getElementById("source");
    var str = srcEl.value;
    var rst = "";
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i)  > 255) {
            rst += "\\u" + toHex(str.charCodeAt(i));
        } else {
            rst += str.charAt(i);
        }
    }
    srcEl.value = rst;
}
function xhex(ch) {
    if ('0'.charCodeAt(0) <= ch && ch <= '9'.charCodeAt(0)) {
        return ch - '0'.charCodeAt(0);
    } else if ('a'.charCodeAt(0) <= ch && ch <= 'f'.charCodeAt(0)) {
        return ch - 'a'.charCodeAt(0) + 10;
    } else if ('A'.charCodeAt(0) <= ch && ch <= 'F'.charCodeAt(0)) {
        return ch - 'A'.charCodeAt(0) + 10;
    }
    return 0;
}
function rtransform() {
    var srcEl = document.getElementById("source");
    var str = srcEl.value;
    var rst = str.replace(/(\\u[0-9A-Fa-f]{4})/ig, function($0) {
        var value = xhex($0.charCodeAt(2)) * 0x1000
                + xhex($0.charCodeAt(3)) * 0x100
                + xhex($0.charCodeAt(4)) * 0x10
                + xhex($0.charCodeAt(5));
        return String.fromCharCode(value);
    });
    srcEl.value = rst;
}
</script>
本记录所在类别:
本记录相关记录: