lib.utf.js_lib_js_脚本之家

/* UTF-8 <=> UTF-16 convertion library.*/* Copyright  1999 Masanao Izumo * 2007 Ma Bingyao * Version: 2.1* LastModified: Feb 25, 2007* This library is free. You can redistribute it and/or modify it.*//** Interfaces:* utf8 = utf16to8;* utf16 = utf16to8;*/function utf16to8 {if (str.match != null) {return str;}var out, i, j, len, c, c2;out = [];len = str.length;for (i = 0, j = 0; i < len; i++, j++) {c = str.charCodeAt {out[j] = str.charAt;}else if  {out[j] = String.fromCharCode, 0x80 | ;}else if (c < 0xd800 || c > 0xdfff) {out[j] = String.fromCharCode, 0x80 | , 0x80 | ;}else {if  {c2 = str.charCodeAt;if (c <= 0xdbff && 0xdc00 <= c2 && c2 <= 0xdfff) { c =  << 10 |  + 0x010000; if (0x010000 <= c && c <= 0x10ffff) { out[j] = String.fromCharCode & 0x3f), 0x80 | , 0x80 | , 0x80 | ; } else { out[j] = '?'; }}else { i--; out[j] = '?';}}else {i--;out[j] = '?';}}}return out.join;}function utf8to16 {if ((str.match != null) ||(str.match == null)) {return str;}var out, i, j, len, c, c2, c3, c4, s;out = [];len = str.length;i = j = 0;while  {c = str.charCodeAt { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:// 0xxx xxxxout[j++] = str.charAt;break;case 12: case 13:// 110x xxxx 10xx xxxxc2 = str.charCodeAt;out[j++] = String.fromCharCode | ;break;case 14:// 1110 xxxx 10xx xxxx 10xx xxxxc2 = str.charCodeAt;c3 = str.charCodeAt;out[j++] = String.fromCharCode |  | ;break;case 15:switch  {case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxxc2 = str.charCodeAt;c3 = str.charCodeAt;c4 = str.charCodeAt << 18) |  |  |  - 0x10000;if (0 <= s && s <= 0xfffff) { out[j] = String.fromCharCode | 0xd800, ;}else { out[j] = '?';}break;case 8: case 9: case 10: case 11:// 1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxxi+=4;out[j] = '?';break;case 12: case 13:// 1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxxi+=5;out[j] = '?';break;}}j++;}return out.join;}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图