| 15 | var Hashes; |
| 16 | |
| 17 | function utf8Encode(str) { |
| 18 | var x, y, output = '', |
| 19 | i = -1, |
| 20 | l; |
| 21 | |
| 22 | if (str && str.length) { |
| 23 | l = str.length; |
| 24 | while ((i += 1) < l) { |
| 25 | /* Decode utf-16 surrogate pairs */ |
| 26 | x = str.charCodeAt(i); |
| 27 | y = i + 1 < l ? str.charCodeAt(i + 1) : 0; |
| 28 | if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { |
| 29 | x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); |
| 30 | i += 1; |
| 31 | } |
| 32 | /* Encode output as utf-8 */ |
| 33 | if (x <= 0x7F) { |
| 34 | output += String.fromCharCode(x); |
| 35 | } else if (x <= 0x7FF) { |
| 36 | output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), |
| 37 | 0x80 | (x & 0x3F)); |
| 38 | } else if (x <= 0xFFFF) { |
| 39 | output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), |
| 40 | 0x80 | ((x >>> 6) & 0x3F), |
| 41 | 0x80 | (x & 0x3F)); |
| 42 | } else if (x <= 0x1FFFFF) { |
| 43 | output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), |
| 44 | 0x80 | ((x >>> 12) & 0x3F), |
| 45 | 0x80 | ((x >>> 6) & 0x3F), |
| 46 | 0x80 | (x & 0x3F)); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | return output; |
| 51 | } |
| 52 | |
| 53 | function utf8Decode(str) { |
| 54 | var i, ac, c1, c2, c3, arr = [], |