兼容低版本IE的JScript5.5实现

2019-06-03 19:56:45王旭
<= 0x007F) { out[j++] = l[c]; continue; } else if (c <= 0x7FF) { out[j++] = '%' + (0xC0 | ((c >> 6) & 0x1F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | ( c & 0x3F)).toString(16).toUpperCase(); continue; } else if (c < 0xD800 || c > 0xDFFF) { out[j++] = '%' + (0xE0 | ((c >> 12) & 0x0F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | ((c >> 6) & 0x3F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | (c & 0x3F)).toString(16).toUpperCase(); continue; } else { if (++i < len) { c2 = str.charCodeAt(i); if (c <= 0xDBFF && 0xDC00 <= c2 && c2 <= 0xDFFF) { c = ((c & 0x03FF) << 10 | (c2 & 0x03FF)) + 0x010000; if (0x010000 <= c && c <= 0x10FFFF) { out[j++] = '%' + (0xF0 | ((c >>> 18) & 0x3F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | ((c >>> 12) & 0x3F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | ((c >>> 6) & 0x3F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | (c & 0x3F)).toString(16).toUpperCase(); continue; } } } } @if (@_jscript_version < 5) return null; @else var e = new Error(-2146823264, "The URI to be encoded contains an invalid character"); e.name = "URIError"; e.message = e.description; throw(e); @end } return out.join(''); } function encodeURIComponent(str) { var l = ['%00', '%01', '%02', '%03', '%04', '%05', '%06', '%07', '%08', '%09', '%0A', '%0B', '%0C', '%0D', '%0E', '%0F', '%10', '%11', '%12', '%13', '%14', '%15', '%16', '%17', '%18', '%19', '%1A', '%1B', '%1C', '%1D', '%1E', '%1F', '%20', '!', '%22', '%23', '%24', '%25', '%26', "'", '(', ')', '*', '%2B', '%2C', '-', '.', '%2F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '%3A', '%3B', '%3C', '%3D', '%3E', '%3F', '%40', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '%5B', '%5C', '%5D', '%5E', '_', '%60', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '%7B', '%7C', '%7D', '~', '%7F']; var out, i, j, len, c; out = []; len = str.length; for(i = 0, j = 0; i < len; i++) { c = str.charCodeAt(i); if (c <= 0x007F) { out[j++] = l[c]; continue; } else if (c <= 0x7FF) { out[j++] = '%' + (0xC0 | ((c >> 6) & 0x1F)).toString(16).toUpperCase(); out[j++] = '%' + (0x80 | ( c & 0x3F)).toString(16).toUpperCase(); continue; } else if (c