daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Gb2312ToUtf8(s1) {
  2.   var s = escape(s1)
  3.   var sa = s.split('%')
  4.   var retV = ''
  5.   if (sa[0] != '') {
  6.     retV = sa[0]
  7.   }
  8.   for (var i = 1; i < sa.length; i++) {
  9.     if (sa[i].substring(0, 1) == 'u') {
  10.       retV += this.Hex2Utf8(this.Str2Hex(sa[i].substring(1, 5)))
  11.       if (sa[i].length) {
  12.         retV += sa[i].substring(5)
  13.       }
  14.     } else {
  15.       retV += unescape('%' + sa[i])
  16.       if (sa[i].length) {
  17.         retV += sa[i].substring(5)
  18.       }
  19.     }
  20.   }
  21.   return retV
  22. }
  23. function Utf8ToGb2312(str1) {
  24.   var substr = ''
  25.   var a = ''
  26.   var b = ''
  27.   var c = ''
  28.   var i = -1
  29.   i = str1.indexOf('%')
  30.   if (i == -1) {
  31.     return str1
  32.   }
  33.   while (i != -1) {
  34.     if (i < 3) {
  35.       substr = substr + str1.substr(0, i - 1)
  36.       str1 = str1.substr(i + 1, str1.length - i)
  37.       a = str1.substr(0, 2)
  38.       str1 = str1.substr(2, str1.length - 2)
  39.       if (parseInt('0x' + a) & (0x80 == 0)) {
  40.         substr = substr + String.fromCharCode(parseInt('0x' + a))
  41.       } else if (parseInt('0x' + a) & (0xe0 == 0xc0)) {
  42.         //two byte
  43.         b = str1.substr(1, 2)
  44.         str1 = str1.substr(3, str1.length - 3)
  45.         var widechar = (parseInt('0x' + a) & 0x1f) << 6
  46.         widechar = widechar | (parseInt('0x' + b) & 0x3f)
  47.         substr = substr + String.fromCharCode(widechar)
  48.       } else {
  49.         b = str1.substr(1, 2)
  50.         str1 = str1.substr(3, str1.length - 3)
  51.         c = str1.substr(1, 2)
  52.         str1 = str1.substr(3, str1.length - 3)
  53.         var widechar = (parseInt('0x' + a) & 0x0f) << 12
  54.         widechar = widechar | ((parseInt('0x' + b) & 0x3f) << 6)
  55.         widechar = widechar | (parseInt('0x' + c) & 0x3f)
  56.         substr = substr + String.fromCharCode(widechar)
  57.       }
  58.     } else {
  59.       substr = substr + str1.substring(0, i)
  60.       str1 = str1.substring(i)
  61.     }
  62.     i = str1.indexOf('%')
  63.   }
  64.  
  65.   return substr + str1
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top