MCPcopy
hub / github.com/IvanMathy/Boop / utf8Decode

Function utf8Decode

Boop/Boop/scripts/lib/hashes.js:53–81  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

51 }
52
53 function utf8Decode(str) {
54 var i, ac, c1, c2, c3, arr = [],
55 l;
56 i = ac = c1 = c2 = c3 = 0;
57
58 if (str && str.length) {
59 l = str.length;
60 str += '';
61
62 while (i < l) {
63 c1 = str.charCodeAt(i);
64 ac += 1;
65 if (c1 < 128) {
66 arr[ac] = String.fromCharCode(c1);
67 i += 1;
68 } else if (c1 > 191 && c1 < 224) {
69 c2 = str.charCodeAt(i + 1);
70 arr[ac] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
71 i += 2;
72 } else {
73 c2 = str.charCodeAt(i + 1);
74 c3 = str.charCodeAt(i + 2);
75 arr[ac] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
76 i += 3;
77 }
78 }
79 }
80 return arr.join('');
81 }
82
83 /**
84 * Add integers, wrapping at 2^32. This uses 16-bit operations internally

Callers 1

hashes.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected