function UTF16toUTF8(inStr){ return inStr.replace(/[^\x00-\x7f]/g, function(chr){ n = chr.charCodeAt(0); return (n < 0x800 ? String.fromCharCode(n >> 6 & 0x1f | 0xc0) : String.fromCharCode(n >> 12 | 0xe0, n >> 6 & 0x3f | 0x80) ) + String.fromCharCode(n & 0x3f | 0x80) }); } function UTF8toUTF16(inStr){ return inStr.replace(/[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]/g, function(chr){ return String.fromCharCode(chr.length == 2 ? (chr.charCodeAt(0) & 0x1f) << 6 | (chr.charCodeAt(1) & 0x3f) : (chr.charCodeAt(0) & 0xf) << 12 | (chr.charCodeAt(1) & 0x3f) << 6 | (chr.charCodeAt(2) & 0x3f) ) }); }