-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserialize.js
520 lines (486 loc) · 21.2 KB
/
serialize.js
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/*
* More info at: http://phpjs.org
*
* This is version: 3.24
* php.js is copyright 2011 Kevin van Zonneveld.
*
* Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
* (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
* (http://getsprink.com), Waldo Malqui Silva, Paulo Freitas, Jonas Raoni
* Soares Silva (http://www.jsfromhell.com), Jack, Philip Peterson, Ates Goral
* (http://magnetiq.com), Legaev Andrey, Ratheous, Alex, Martijn Wieringa,
* Nate, lmeyrick (https://sourceforge.net/projects/bcmath-js/), Enrique
* Gonzalez, Philippe Baumann, Rafał Kukawski (http://blog.kukawski.pl),
* Webtoolkit.info (http://www.webtoolkit.info/), Ole Vrijenhoek, Ash Searle
* (http://hexmen.com/blog/), travc, Carlos R. L. Rodrigues
* (http://www.jsfromhell.com), Jani Hartikainen, stag019, GeekFG
* (http://geekfg.blogspot.com), WebDevHobo (http://webdevhobo.blogspot.com/),
* Erkekjetter, pilus, Rafał Kukawski (http://blog.kukawski.pl/), Johnny Mast
* (http://www.phpvrouwen.nl), T.Wild,
* http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
* d3x, Michael Grier, Andrea Giammarchi (http://webreflection.blogspot.com),
* marrtins, Mailfaker (http://www.weedem.fr/), Steve Hilder, gettimeofday,
* mdsjack (http://www.mdsjack.bo.it), felix, majak, Steven Levithan
* (http://blog.stevenlevithan.com), Mirek Slugen, Oleg Eremeev, Felix
* Geisendoerfer (http://www.debuggable.com/felix), Martin
* (http://www.erlenwiese.de/), gorthaur, Lars Fischer, Joris, AJ, Paul Smith,
* Tim de Koning (http://www.kingsquare.nl), KELAN, Josh Fraser
* (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
* Chris, Marc Palau, Kevin van Zonneveld (http://kevin.vanzonneveld.net/),
* Arpad Ray (mailto:[email protected]), Breaking Par Consulting Inc
* (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
* Nathan, Karol Kowalski, David, Dreamer, Diplom@t (http://difane.com/), Caio
* Ariede (http://caioariede.com), Robin, Imgen Tata (http://www.myipdf.com/),
* Pellentesque Malesuada, saulius, Aman Gupta, Sakimori, Tyler Akins
* (http://rumkin.com), Thunder.m, Public Domain
* (http://www.json.org/json2.js), Michael White, Kankrelune
* (http://www.webfaktory.info/), Alfonso Jimenez
* (http://www.alfonsojimenez.com), Frank Forte, vlado houba, Marco, Billy,
* David James, madipta, noname, sankai, class_exists, Jalal Berrami, ger,
* Itsacon (http://www.itsacon.net/), Scott Cariss, nobbler, Arno, Denny
* Wardhana, ReverseSyntax, Mateusz "loonquawl" Zalega, Slawomir Kaniecki,
* Francois, Fox, mktime, Douglas Crockford (http://javascript.crockford.com),
* john (http://www.jd-tech.net), Oskar Larsson Högfeldt
* (http://oskar-lh.name/), marc andreu, Nick Kolosov (http://sammy.ru), date,
* Marc Jansen, Steve Clay, Olivier Louvignes (http://mg-crea.com/), Soren
* Hansen, merabi, Subhasis Deb, josh, T0bsn, Tim Wiel, Brad Touesnard, MeEtc
* (http://yass.meetcweb.com), Peter-Paul Koch
* (http://www.quirksmode.org/js/beat.html), Pyerre, Jon Hohle, duncan, Bayron
* Guevara, Adam Wallner (http://web2.bitbaro.hu/), paulo kuong, Gilbert,
* Lincoln Ramsay, Thiago Mata (http://thiagomata.blog.com), Linuxworld,
* lmeyrick (https://sourceforge.net/projects/bcmath-js/this.), djmix, Bryan
* Elliott, David Randall, Sanjoy Roy, jmweb, Francesco, Stoyan Kyosev
* (http://www.svest.org/), J A R, kenneth, T. Wild, Ole Vrijenhoek
* (http://www.nervous.nl/), Raphael (Ao RUDLER), Shingo, LH, JB, nord_ua, jd,
* JT, Thomas Beaucourt (http://www.webapp.fr), Ozh, XoraX
* (http://www.xorax.info), EdorFaus, Eugene Bulkin (http://doubleaw.com/),
* Der Simon (http://innerdom.sourceforge.net/), 0m3r, echo is bad,
* FremyCompany, stensi, Kristof Coomans (SCK-CEN Belgian Nucleair Research
* Centre), Devan Penner-Woelk, Pierre-Luc Paour, Martin Pool, Brant Messenger
* (http://www.brantmessenger.com/), Kirk Strobeck, Saulo Vallory, Christoph,
* Wagner B. Soares, Artur Tchernychev, Valentina De Rosa, Jason Wong
* (http://carrot.org/), Daniel Esteban, strftime, Rick Waldron, Mick@el,
* Anton Ongson, Bjorn Roesbeke (http://www.bjornroesbeke.be/), Simon Willison
* (http://simonwillison.net), Gabriel Paderni, Philipp Lenssen, Marco van
* Oort, Bug?, Blues (http://tech.bluesmoon.info/), Tomasz Wesolowski, rezna,
* Eric Nagel, Evertjan Garretsen, Luke Godfrey, Pul, Bobby Drake, uestla,
* Alan C, Ulrich, Zahlii, Yves Sucaet, sowberry, Norman "zEh" Fuchs, hitwork,
* johnrembo, Brian Tafoya (http://www.premasolutions.com/), Nick Callen,
* Steven Levithan (stevenlevithan.com), ejsanders, Scott Baker, Philippe
* Jausions (http://pear.php.net/user/jausions), Aidan Lister
* (http://aidanlister.com/), Rob, e-mike, HKM, ChaosNo1, metjay, strcasecmp,
* strcmp, Taras Bogach, jpfle, Alexander Ermolaev
* (http://snippets.dzone.com/user/AlexanderErmolaev), DxGx, kilops, Orlando,
* dptr1988, Le Torbi, James (http://www.james-bell.co.uk/), Pedro Tainha
* (http://www.pedrotainha.com), James, penutbutterjelly, Arnout Kazemier
* (http://www.3rd-Eden.com), 3D-GRAF, daniel airton wermann
* (http://wermann.com.br), jakes, Yannoo, FGFEmperor, gabriel paderni, Atli
* Þór, Maximusya, Diogo Resende, Rival, Howard Yeend, Allan Jensen
* (http://www.winternet.no), davook, Benjamin Lupton, baris ozdil, Greg
* Frazier, Manish, Matt Bradley, Cord, fearphage
* (http://http/my.opera.com/fearphage/), Matteo, Victor, taith, Tim de
* Koning, Ryan W Tenney (http://ryan.10e.us), Tod Gentille, Alexander M
* Beedie, Riddler (http://www.frontierwebdev.com/), Luis Salazar
* (http://www.freaky-media.com/), Rafał Kukawski, T.J. Leahy, Luke Smith
* (http://lucassmith.name), Kheang Hok Chin (http://www.distantia.ca/),
* Russell Walker (http://www.nbill.co.uk/), Jamie Beck
* (http://www.terabit.ca/), Garagoth, Andrej Pavlovic, Dino, Le Torbi
* (http://www.letorbi.de/), Ben (http://benblume.co.uk/), DtTvB
* (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Michael, Chris
* McMacken, setcookie, YUI Library:
* http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Andreas,
* Blues at http://hacks.bluesmoon.info/strftime/strftime.js, rem, Josep Sanz
* (http://www.ws3.es/), Cagri Ekin, Lorenzo Pisani, incidence, Amirouche, Jay
* Klehr, Amir Habibi (http://www.residence-mixte.com/), Tony, booeyOH, meo,
* William, Greenseed, Yen-Wei Liu, Ben Bryan, Leslie Hoare, mk.keck
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// jslint.com configuration options. See: http://wiki.github.com/kvz/phpjs/jslint-options
/* global window */
/* jslint adsafe: false, bitwise: false, browser: false, cap: false, css: false, debug: false, devel: false, eqeqeq: true, evil: false, forin: false, fragment: false, immed: true, indent: 4, laxbreak: false, maxerr: 100, maxlen: 80, newcap: true, nomen: false, on: true, onevar: false, passfail: false, plusplus: false, regexp: false, rhino: false, safe: false, sidebar: false, strict: false, sub: false, undef: true, white: false, widget: false */
// Our idea with CommonJS is that you can do the following:
// var php = require('php');
// php.md5('test');
exports.serialize = function (mixed_value) {
// Returns a string representation of variable (which can later be unserialized)
//
// version: 1103.1210
// discuss at: http://phpjs.org/functions/serialize
// + original by: Arpad Ray (mailto:[email protected])
// + improved by: Dino
// + bugfixed by: Andrej Pavlovic
// + bugfixed by: Garagoth
// + input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html)
// + bugfixed by: Russell Walker (http://www.nbill.co.uk/)
// + bugfixed by: Jamie Beck (http://www.terabit.ca/)
// + input by: Martin (http://www.erlenwiese.de/)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/)
// + improved by: Le Torbi (http://www.letorbi.de/)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/)
// + bugfixed by: Ben (http://benblume.co.uk/)
// - depends on: utf8_encode
// % note: We feel the main purpose of this function should be to ease the transport of data between php & js
// % note: Aiming for PHP-compatibility, we have to translate objects to arrays
// * example 1: \php.serialize(['Kevin', 'van', 'Zonneveld']);
// * returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
// * example 2: \php.serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
// * returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
var _utf8Size = function (str) {
var size = 0,
i = 0,
l = str.length,
code = '';
for (i = 0; i < l; i++) {
code = str.charCodeAt(i);
if (code < 0x0080) {
size += 1;
} else if (code < 0x0800) {
size += 2;
} else {
size += 3;
}
}
return size;
};
var _getType = function (inp) {
var type = typeof inp,
match;
var key;
if (type === 'object' && !inp) {
return 'null';
}
if (type === "object") {
if (!inp.constructor) {
return 'object';
}
var cons = inp.constructor.toString();
match = cons.match(/(\w+)\(/);
if (match) {
cons = match[1].toLowerCase();
}
var types = ["boolean", "number", "string", "array"];
for (key in types) {
if (cons == types[key]) {
type = types[key];
break;
}
}
}
return type;
};
var type = _getType(mixed_value);
var val, ktype = '';
switch (type) {
case "function":
val = "";
break;
case "boolean":
val = "b:" + (mixed_value ? "1" : "0");
break;
case "number":
val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
break;
case "string":
val = "s:" + _utf8Size(mixed_value) + ":\"" + mixed_value + "\"";
break;
case "array":
case "object":
val = "a";
/*
if (type == "object") {
var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
if (objname == undefined) {
return;
}
objname[1] = this.serialize(objname[1]);
val = "O" + objname[1].substring(1, objname[1].length - 1);
}
*/
var count = 0;
var vals = "";
var okey;
var key;
for (key in mixed_value) {
if (mixed_value.hasOwnProperty(key)) {
ktype = _getType(mixed_value[key]);
if (ktype === "function") {
continue;
}
okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
vals += this.serialize(okey) + this.serialize(mixed_value[key]);
count++;
}
}
val += ":" + count + ":{" + vals + "}";
break;
case "undefined":
// Fall-through
default:
// if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
val = "N";
break;
}
if (type !== "object" && type !== "array") {
val += ";";
}
return val;
};
exports.unserialize = function (data) {
// Takes a string representation of variable and recreates it
//
// version: 1103.1210
// discuss at: http://phpjs.org/functions/unserialize
// + original by: Arpad Ray (mailto:[email protected])
// + improved by: Pedro Tainha (http://www.pedrotainha.com)
// + bugfixed by: dptr1988
// + revised by: d3x
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + input by: Brett Zamir (http://brett-zamir.me)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Chris
// + improved by: James
// + input by: Martin (http://www.erlenwiese.de/)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Le Torbi
// + input by: kilops
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// - depends on: utf8_decode
// % note: We feel the main purpose of this function should be to ease the transport of data between php & js
// % note: Aiming for PHP-compatibility, we have to translate objects to arrays
// * example 1: \php.unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');
// * returns 1: ['Kevin', 'van', 'Zonneveld']
// * example 2: \php.unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');
// * returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}
var that = this;
var utf8Overhead = function (chr) {
// http://phpjs.org/functions/unserialize:571#comment_95906
var code = chr.charCodeAt(0);
if (code < 0x0080) {
return 0;
}
if (code < 0x0800) {
return 1;
}
return 2;
};
var error = function (type, msg, filename, line) {
throw new that.window[type](msg, filename, line);
};
var read_until = function (data, offset, stopchr) {
var buf = [];
var chr = data.slice(offset, offset + 1);
var i = 2;
while (chr != stopchr) {
if ((i + offset) > data.length) {
error('Error', 'Invalid');
}
buf.push(chr);
chr = data.slice(offset + (i - 1), offset + i);
i += 1;
}
return [buf.length, buf.join('')];
};
var read_chrs = function (data, offset, length) {
var buf;
buf = [];
for (var i = 0; i < length; i++) {
var chr = data.slice(offset + (i - 1), offset + i);
buf.push(chr);
length -= utf8Overhead(chr);
}
return [buf.length, buf.join('')];
};
var _unserialize = function (data, offset) {
var readdata;
var readData;
var chrs = 0;
var ccount;
var stringlength;
var keyandchrs;
var keys;
if (!offset) {
offset = 0;
}
var dtype = (data.slice(offset, offset + 1)).toLowerCase();
var dataoffset = offset + 2;
var typeconvert = function (x) {
return x;
};
switch (dtype) {
case 'i':
typeconvert = function (x) {
return parseInt(x, 10);
};
readData = read_until(data, dataoffset, ';');
chrs = readData[0];
readdata = readData[1];
dataoffset += chrs + 1;
break;
case 'b':
typeconvert = function (x) {
return parseInt(x, 10) !== 0;
};
readData = read_until(data, dataoffset, ';');
chrs = readData[0];
readdata = readData[1];
dataoffset += chrs + 1;
break;
case 'd':
typeconvert = function (x) {
return parseFloat(x);
};
readData = read_until(data, dataoffset, ';');
chrs = readData[0];
readdata = readData[1];
dataoffset += chrs + 1;
break;
case 'n':
readdata = null;
break;
case 's':
ccount = read_until(data, dataoffset, ':');
chrs = ccount[0];
stringlength = ccount[1];
dataoffset += chrs + 2;
readData = read_chrs(data, dataoffset + 1, parseInt(stringlength, 10));
chrs = readData[0];
readdata = readData[1];
dataoffset += chrs + 2;
if (chrs != parseInt(stringlength, 10) && chrs != readdata.length) {
error('SyntaxError', 'String length mismatch');
}
// Length was calculated on an utf-8 encoded string
// so wait with decoding
readdata = that.utf8_decode(readdata);
break;
case 'a':
readdata = {};
keyandchrs = read_until(data, dataoffset, ':');
chrs = keyandchrs[0];
keys = keyandchrs[1];
dataoffset += chrs + 2;
for (var i = 0; i < parseInt(keys, 10); i++) {
var kprops = _unserialize(data, dataoffset);
var kchrs = kprops[1];
var key = kprops[2];
dataoffset += kchrs;
var vprops = _unserialize(data, dataoffset);
var vchrs = vprops[1];
var value = vprops[2];
dataoffset += vchrs;
readdata[key] = value;
}
dataoffset += 1;
break;
default:
error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
break;
}
return [dtype, dataoffset - offset, typeconvert(readdata)];
};
return _unserialize((data + ''), 0)[2];
};
exports.utf8_decode = function (str_data) {
// Converts a UTF-8 encoded string to ISO-8859-1
//
// version: 1103.1210
// discuss at: http://phpjs.org/functions/utf8_decode
// + original by: Webtoolkit.info (http://www.webtoolkit.info/)
// + input by: Aman Gupta
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Norman "zEh" Fuchs
// + bugfixed by: hitwork
// + bugfixed by: Onno Marsman
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// * example 1: \php.utf8_decode('Kevin van Zonneveld');
// * returns 1: 'Kevin van Zonneveld'
var tmp_arr = [],
i = 0,
ac = 0,
c1 = 0,
c2 = 0,
c3 = 0;
str_data += '';
while (i < str_data.length) {
c1 = str_data.charCodeAt(i);
if (c1 < 128) {
tmp_arr[ac++] = String.fromCharCode(c1);
i++;
} else if (c1 > 191 && c1 < 224) {
c2 = str_data.charCodeAt(i + 1);
tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = str_data.charCodeAt(i + 1);
c3 = str_data.charCodeAt(i + 2);
tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return tmp_arr.join('');
};
exports.utf8_encode = function (argString) {
// Encodes an ISO-8859-1 string to UTF-8
//
// version: 1103.1210
// discuss at: http://phpjs.org/functions/utf8_encode
// + original by: Webtoolkit.info (http://www.webtoolkit.info/)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: sowberry
// + tweaked by: Jack
// + bugfixed by: Onno Marsman
// + improved by: Yves Sucaet
// + bugfixed by: Onno Marsman
// + bugfixed by: Ulrich
// * example 1: \php.utf8_encode('Kevin van Zonneveld');
// * returns 1: 'Kevin van Zonneveld'
var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
var utftext = "",
start, end, stringl = 0;
start = end = 0;
stringl = string.length;
for (var n = 0; n < stringl; n++) {
var c1 = string.charCodeAt(n);
var enc = null;
if (c1 < 128) {
end++;
} else if (c1 > 127 && c1 < 2048) {
enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
} else {
enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
}
if (enc !== null) {
if (end > start) {
utftext += string.slice(start, end);
}
utftext += enc;
start = end = n + 1;
}
}
if (end > start) {
utftext += string.slice(start, stringl);
}
return utftext;
};