fffec1d8-8f9b-4228-88b5-8dc73c3c97a6.js
8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"use strict";
cc._RF.push(module, 'fffecHYj5tCKIi1jcc8PJem', 'StringUtils');
// script/common/utils/StringUtils.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringUtils = void 0;
var StringUtils;
(function (StringUtils) {
function getUrlParam(key) {
if (!window.location.search) {
return ""; //微信版本没有此变量
}
const reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
const r = window.location.search.substr(1).match(reg);
if (r != null)
return decodeURI(r[2]);
return "";
}
StringUtils.getUrlParam = getUrlParam;
//js实现用传递的值替换占位符{0} {1} {2}
function format(str, ...args) {
if (args.length == 0)
return str;
for (let i = 0; i < args.length; i++)
str = str.replace(new RegExp("\\{" + i + "\\}", "g"), args[i]);
return str;
}
StringUtils.format = format;
function str_repeat(i, m) {
for (var o = []; m > 0; o[--m] = i)
;
return o.join('');
}
StringUtils.str_repeat = str_repeat;
function sprintf(fmt, ...params) {
var i = 0, a, f = fmt, o = [], m, p, c, x, s = '';
while (f) {
if (m = /^[^\x25]+/.exec(f)) {
o.push(m[0]);
}
else if (m = /^\x25{2}/.exec(f)) {
o.push('%');
}
else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
if (((a = params[(m[1] - 1) || i++]) == null) || (a == undefined)) {
throw ('Too few arguments.');
}
if (/[^s]/.test(m[7]) && (typeof (a) != 'number')) {
throw ('Expecting number but found ' + typeof (a));
}
switch (m[7]) {
case 'b':
a = a.toString(2);
break;
case 'c':
a = String.fromCharCode(a);
break;
case 'd':
a = parseInt(a);
break;
case 'e':
a = m[6] ? a.toExponential(m[6]) : a.toExponential();
break;
case 'f':
a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a);
break;
case 'o':
a = a.toString(8);
break;
case 's':
a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a);
break;
case 'u':
a = Math.abs(a);
break;
case 'x':
a = a.toString(16);
break;
case 'X':
a = a.toString(16).toUpperCase();
break;
}
a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+' + a : a);
c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
x = m[5] - String(a).length - s.length;
p = m[5] ? str_repeat(c, x) : '';
o.push(s + (m[4] ? a + p : p + a));
}
else {
throw ('Huh ?!');
}
f = f.substring(m[0].length);
}
return o.join('');
}
StringUtils.sprintf = sprintf;
function utf8ArrToStr(aBytes) {
var sView = "";
for (var nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) {
nPart = aBytes[nIdx];
sView += String.fromCharCode(nPart > 251 && nPart < 254
&& nIdx + 5 < nLen ? /* six bytes */
/* (nPart - 252 << 32) is not possible in ECMAScript! So...: */
(nPart - 252) * 1073741824 + (aBytes[++nIdx] - 128 << 24)
+ (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12)
+ (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
: nPart > 247 && nPart < 252 && nIdx + 4 < nLen ? /*
* five
* bytes
*/
(nPart - 248 << 24) + (aBytes[++nIdx] - 128 << 18)
+ (aBytes[++nIdx] - 128 << 12)
+ (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
: nPart > 239 && nPart < 248 && nIdx + 3 < nLen ? /*
* four
* bytes
*/
(nPart - 240 << 18) + (aBytes[++nIdx] - 128 << 12)
+ (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx]
- 128 : nPart > 223 && nPart < 240
&& nIdx + 2 < nLen ? /* three bytes */
(nPart - 224 << 12) + (aBytes[++nIdx] - 128 << 6)
+ aBytes[++nIdx] - 128 : nPart > 191
&& nPart < 224 && nIdx + 1 < nLen ? /* two bytes */
(nPart - 192 << 6) + aBytes[++nIdx] - 128 : /*
* nPart <
* 127 ?
*/ /*
* one byte
*/
nPart);
}
return sView;
}
StringUtils.utf8ArrToStr = utf8ArrToStr;
function strToUtf8Arr(sDOMStr) {
var aBytes, nChr, nStrLen = sDOMStr.length, nArrLen = 0;
/* mapping... */
for (var nMapIdx = 0; nMapIdx < nStrLen; nMapIdx++) {
nChr = sDOMStr.charCodeAt(nMapIdx);
nArrLen += nChr < 0x80 ? 1 : nChr < 0x800 ? 2 : nChr < 0x10000 ? 3
: nChr < 0x200000 ? 4 : nChr < 0x4000000 ? 5 : 6;
}
aBytes = new Uint8Array(nArrLen);
/* transcription... */
for (var nIdx = 0, nChrIdx = 0; nIdx < nArrLen; nChrIdx++) {
nChr = sDOMStr.charCodeAt(nChrIdx);
if (nChr < 128) {
/* one byte */
aBytes[nIdx++] = nChr;
}
else if (nChr < 0x800) {
/* two bytes */
aBytes[nIdx++] = 192 + (nChr >>> 6);
aBytes[nIdx++] = 128 + (nChr & 63);
}
else if (nChr < 0x10000) {
/* three bytes */
aBytes[nIdx++] = 224 + (nChr >>> 12);
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
aBytes[nIdx++] = 128 + (nChr & 63);
}
else if (nChr < 0x200000) {
/* four bytes */
aBytes[nIdx++] = 240 + (nChr >>> 18);
aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
aBytes[nIdx++] = 128 + (nChr & 63);
}
else if (nChr < 0x4000000) {
/* five bytes */
aBytes[nIdx++] = 248 + (nChr >>> 24);
aBytes[nIdx++] = 128 + (nChr >>> 18 & 63);
aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
aBytes[nIdx++] = 128 + (nChr & 63);
}
else /* if (nChr <= 0x7fffffff) */ {
/* six bytes */
aBytes[nIdx++] = 252 + /*
* (nChr >>> 32) is not possible in
* ECMAScript! So...:
*/
(nChr / 1073741824);
aBytes[nIdx++] = 128 + (nChr >>> 24 & 63);
aBytes[nIdx++] = 128 + (nChr >>> 18 & 63);
aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
aBytes[nIdx++] = 128 + (nChr & 63);
}
}
return aBytes;
}
StringUtils.strToUtf8Arr = strToUtf8Arr;
})(StringUtils = exports.StringUtils || (exports.StringUtils = {}));
cc._RF.pop();