JS (Unicode-> GB) Lite (still pinyin and urlencode)

zhaozj2021-02-16  48

http://www.9cbs.net/develop/read_article.asp?id=15043 Unicode and GB convert libraries with the following address http://www.blueidea.com/user/qswh/qswhu2gb.js148k JS, local There is no problem with the test, but it will feel a little slow on the Internet.

So a streamlined version is recorded, which is only GB2312 encoding, i.e., part GBK, but it can be specially streamlined this time, but the function is constant, the difference is that this version can only act on common Chinese characters. What horse is with what saddle, also modified Urlencode and GetSpell algorithm, please don't confuse. This time qswhgb2312.js is only 18K, which can be used online.

Unicode and GB convert libraries and urlencode and getspell functions, please download http://www.blueidea.com/user/qswh/qswhgb2312.js

The main code is the following var strgb = "ah ... snoring"; // GB2312 string, slight var qswhspell = ["a", 0, .., "zuo", 3747]; // Pinyin comparison table , Slight function urlencode (str) {var i, c, p, q, return = "", strspecial = "! # $% & '() * , / :; <=>? @ [/] ^ `{|} ~%"; For (i = 0; i = 0x4e00) {var p = strgb.indexof (Str.Charat (i)) ; If (p> = 0) {q = p% 94; P = (pq) / 94; RET = ("%" (0xB0 P) .tostring (16) "%" (0xA1 Q) .tostring (16)). TouPpercase ();}} else {c = str.Charat (i); if (c == ") RET =" "; Else IF (strspecial.indexof (c)! = - 1) RET = "%" str.charcodeat (i) .tostring (16); else Ret = C;}} return ret;

Function GetSpell (STR, SP) {VAR I, C, T, P, RET = ""; if (sp == null) sp = ""; for (i = 0; i = 0x4e00) {p = strgb.indexof (Str.Charat (i)); if (p> -1 && p <3755) {for (t = qswhspell.length-1; t> 0; T = T-2) IF (qswhspell [t] <= p) Break; if (t> 0) RET = QSWHSPELL [T-1] sp;}}} Return Ret.Substr (0, Ret.Length-SP .length);} SP is separator, examples are as follows