/
unicode.js
830 lines (772 loc) · 27.6 KB
/
unicode.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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
/**
* @fileOverview <title>PointedEars' JSX: String Library -- Unicode Support</title>
* @file $Id$
* @requires object.js
*
* @section {Abstract}
*
* A value of the primitive type {@link String} is defined in
* ECMAScript, Editions 1 to 5.1 inclusive, as a sequence of 16-bit
* units. Each unit is assumed, unless specified otherwise, to be
* the UTF-16 code sequence for a Unicode character. The length
* of a String is defined as the number of 16-bit units in the
* value, and the position of a character is defined as the position
* of the corresponding 16-bit unit in the String value.
*
* However, Unicode characters with code points beyond the Basic
* Multilingual Plane (BMP) require two UTF-16 code units, thus two
* 16-bit units, to be encoded. This makes it hard to use them
* in ECMAScript because they are not considered by ECMAScript's
* string-related algorithms. For example, for a string value that
* contains only one character but that has a code point beyond
* the BMP (“non-BMP character”), the specified length and the value
* of the <code>length</code> property is <code>2</code>.
* Retrieving the (code point of the) first character from a string
* with <code>{@link String.prototype.charAt}(0)</code>.
* where the character has a code point beyond the multilingual
* plane, returns the (code point of the) (non-)character for its
* <em>lead surrogate</em>. Retrieving with
* <code>{@link String.prototype.charAt}(1)</code>
* the (code point of) the second character from a string that
* contains a first non-BMP character returns the first character's
* <em>trail surrogate</em> instead.
* {@link String.fromCharCode()} returns the character for the
* normalized code point value for arguments that are code point
* values beyond the BMP (e.g., <code>String.fromCharCode(0x1DD1E)
* === "\uDD1E"</code>).
*
* This library provides a new object type, <code>WideString</code>,
* whose prototype inherits from the <code>String</code>
* prototype, that is intended to be used as a drop-in
* replacement for <code>String</code> values that may contain
* Unicode characters from both inside and beyond the BMP, from
* code points U+0000 to U+10FFFF inclusive.
*
* It also replaces by default the values of certain built-in
* properties of the <code>String</code> constructor and
* <code>String</code> prototype such as the ones mentioned
* above, and adds others to the String prototype, so as to
* support non-BMP characters as well in implementations of those
* ECMAScript Editions almost seamlessly. However, non-callable
* built-in own and inherited properties of <code>String</code>
* values, like <code>length</code>, <em>cannot</em> be modified.
* (In case of <code>length</code>, you would need to use
* <code>getLength()</code> instead.) Whether and to what extent
* built-in objects are modified, can be controlled with
* {@link jsx.options}. (See {@link "object.js"} for details.)
*
* Your feedback is appreciated.
*
* <em>NOTE: The maximum supported string length is limited by
* the maximum supported {@link Array} length, which is 2³²−1
* at the time of writing.</em>
*
* @section {Copyright & Disclaimer}
*
* @author (C) 2013, 2014 Thomas Lahn <js@PointedEars.de>
*
* @partof PointedEars' JavaScript Extensions (JSX)
*
* JSX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JSX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with JSX. If not, see <http://www.gnu.org/licenses/>.
*/
if (typeof jsx.string == "undefined")
{
/**
* @namespace
*/
jsx.string = {};
}
/**
* @namespace
*/
jsx.string.unicode = (/** @constructor */ function () {
/* Imports */
var String_prototype_charCodeAt = "".charCodeAt;
var _isArray = jsx.object.isArray;
/* Handles characters in UTF-16 encoding from U+0000 to U+10FFFF */
var _rx_wide_string = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
var _rx_comb_dia = /\u0300-\u036F/;
var _rx_comb_dia_ext = /\u1AB0-\u1ABE/;
var _rx_comb_dia_supp = /\u1DC0-\u1DF5\u1DFC-\u1DFF/;
var _rx_comb_dia_sym = /\u20D0-\u20F0/;
var _rx_comb_half = /\uFE20-\uFE2D/;
var _rx_combining = new RegExp("["
+ _rx_comb_dia.source
+ _rx_comb_dia_ext.source
+ _rx_comb_dia_supp.source
+ _rx_comb_dia_sym.source
+ _rx_comb_half.source
+ "]");
var _rx_string = new RegExp(
"(" + _rx_wide_string.source
+ "|"
+ /[\S\s]/.source + ")"
+ _rx_combining.source + "*",
"g");
var _BigArray = jsx.object.getFeature(jsx, "array", "BigArray");
/**
* @private
* @param {String} s
* String to be split into an array of characters
* @return {Array}
*/
function _toCharArray (s)
{
if (_BigArray)
{
return (s
? _BigArray.fromChars(s, _rx_string)
: new _BigArray());
}
return (s ? (String(s).match(_rx_string) || []) : []);
}
function _getCharAt (a, index)
{
return _BigArray ? a.get(index) : a[index];
}
function _charCodeAt (position)
{
var ch = this.charAt(position);
if (typeof ch == "undefined")
{
return NaN;
}
if (new RegExp("^" + _rx_wide_string.source).test(ch))
{
var leadSurrogate = String_prototype_charCodeAt.call(ch, 0);
var trailSurrogate = String_prototype_charCodeAt.call(ch, 1);
var leadBits = (leadSurrogate - 0xD800) << 10;
var trailBits = trailSurrogate - 0xDC00;
var bmpOffset = 0x10000;
return leadBits + trailBits + bmpOffset;
}
return String_prototype_charCodeAt.call(ch, 0);
}
/**
* Converts a {@link String} value to a wide string.
* <p>
* A <code>WideString</code> supports all operations and methods
* supported on <code>String</code> values also for Unicode
* characters outside the Basic Multilingual Plane (BMP), that
* is, code points from U+0000 to U+10FFFF inclusive. Because
* strings of characters are stored as an {@link Array} of
* <code>String</code>s, operations where such characters are
* more common are faster than with the <code>String</code>
* prototype augmentation. In other cases you should use
* the augmentation instead.
* </p><p>
* You may call a <code>WideString</code>'s
* {@link WideString.prototype.toString toString()} method
* (implicitly called in string context, like concatenation)
* to convert it back to a <code>String</code> value.
* </p><p>
* * <em>NOTE: The maximum supported string length is limited by
* the maximum supported {@link Array} length, which is 2³²−1
* at the time of writing. Also note that normalization
* is <strong>not</strong> performed.</em>
* </p>
* @extends String
* @constructor
*/
var _WideString = (
/**
* @param {String} s
* @return {jsx.string.unicode.WideString}
*/
function jsx_string_unicode_WideString (s) {
/* Factory support */
if (!(this instanceof jsx_string_unicode_WideString))
{
return new jsx_string_unicode_WideString(s);
}
/**
* @private
* @type Array
*/
var _chars =
_isArray(s)
? s
: (s instanceof jsx_string_unicode_WideString
? s.getChars()
: _toCharArray(s));
/**
* Returns the characters in this object as an {@link Array}
* of {@link String}s.
*
* @protected
* @return {Array}
*/
this.getChars = function () {
return _chars;
},
/**
* @field
* @name chars
* @type Array
* @memberOf jsx.string.unicode.WideString
* @see #getChars()
*/
jsx.object.defineProperty(this, "chars", {"get": this.getChars});
}
).extend(String, {
/**
* Returns the character at the specified position.
*
* <em>NOTE: A single Unicode character may be composed out of
* several other characters. Normalization is not performed.</em>
*
* @memberOf jsx.string.unicode.WideString.prototype
* @param {int} position
* If not an integer, replaced with the closest integer.
* @return {string}
* If <code><var>position</var></code> is greater than or
* equal to zero, the character at that position, counted
* from zero.
* If <code><var>position</var></code> is less than zero,
* it is treated as the number of characters in this object
* + <code><var>position</var></code>; that is,
* <code><var>position</var> === -1</code>
* returns the last character.
* If <code><var>position</var></code> is replaceable with
* an integer out of this range, <code>undefined</code>
* is returned.
* By contrast, if <code><var>position</var></code> is
* not a <code>Number</code>, the return value is
* <strong>not defined</strong>.
*/
charAt: function (position) {
var chars = this.getChars();
position = (position < 0 ? Math.ceil(position) : Math.floor(position));
return (position < 0
? _getCharAt(chars, chars.length + position)
: _getCharAt(chars, position));
},
/**
* Returns the Unicode code point value of the character
* in this object at the specified position.
*
* <em>NOTE: A single Unicode character may be composed out of
* several other characters. Normalization is not performed.
* If you need the code points of combining marks as well,
* use {@link #codePointsAt()}.</em>
*
* @memberOf jsx.string.unicode.WideString.prototype
* @param {Number} position
* If not an integer, replaced with the closest integer.
* @return {number}
* If <code><var>position</var></code> is greater than or
* equal to zero, the code point value of the character
* at that position, counted from zero.
* If <code><var>position</var></code> is less than zero,
* it is treated as the number of characters in this object
* + <code><var>position</var></code>; that is,
* <code><var>position</var> === -1</code>
* returns the code point value of the last character.
* If <code><var>position</var></code> is replacable with
* an integer value out of this range, <code>NaN</code>
* is returned.
* By contrast, if <code><var>position</var></code> is
* not a <code>Number</code>, the return value is
* <strong>not defined</strong>.
* @see #charAt()
*/
charCodeAt: _charCodeAt,
codePointAt: _charCodeAt,
/**
* Returns the Unicode code point values of the character
* in this object at the specified position, followed by
* those of optional combining marks.
*
* @param {Number} position
* If not an integer, replaced with the closest integer.
* @return {Array[number]}
*/
codePointsAt: function (position) {
var first_code_point = this.codePointAt(position);
var result = [first_code_point];
var _char = this.charAt(position);
var m;
var rx_combining_global = new RegExp(_rx_combining.source, "g");
while ((m = rx_combining_global.exec(_char)))
{
result.push(m[0].charCodeAt(0));
}
return result;
},
/**
* Concatenates this string with other strings
* and returns the result.
*
* Returns the <code>WideString</code> resulting from
* concatenating the list of characters in this object with
* the list of the arguments' characters.
*
* @function
*/
concat: (function () {
var _slice = [].slice;
/**
* @params {WideString|String}
* @return {WideString}
*/
function _concat ()
{
return new this.constructor(this.toString()
+ _slice.call(arguments).join(""));
}
return _concat;
}()),
/**
* Returns the number of characters in this string
*
* @return {int}
* @see #length
*/
getLength: function () {
return this.getChars().length;
},
/**
* Returns the index of the first position of a substring
* in this string.
*
* @param {jsx.string.unicode.WideString|String} searchString
* Substring to look for.
* @param {int} position
* Position from where to start searching. The default is
* <code>0</code>.
* @return {number}
*/
indexOf: function (searchString, position) {
var needleChars = searchString instanceof this.constructor
? searchString.getChars()
: _toCharArray(searchString);
var needleLen = needleChars.length;
var needleString = needleChars.join("");
var chars = this.getChars();
for (var i = (typeof position == "undefined"
? 0
: (position < 0 ? 0 : Math.floor(position))),
len = chars.length - needleLen + 1;
i < len; ++i)
{
if (chars.slice(i, i + needleLen).join("") == needleString)
{
return i;
}
}
return -1;
},
/**
* Returns the index of the last position of a substring
* in this string.
*
* @param {jsx.string.unicode.WideString|String} searchString
* Substring to look for.
* @param {int} position
* Position from where to start searching backwards.
* The default is the position of the last character.
* @return {number}
*/
lastIndexOf: function (searchString, position) {
var needleChars = searchString instanceof this.constructor
? searchString.getChars()
: _toCharArray(searchString);
var needleLen = needleChars.length;
var needleString = needleChars.join("");
var chars = this.getChars();
for (var i = (typeof position == "undefined"
? chars.length - needleLen
: (position < 0 ? 0 : Math.floor(position)))
+ 1;
i--;)
{
if (chars.slice(i, i + needleLen).join("") == needleString)
{
return i;
}
}
return -1;
},
/**
* Returns a slice (substring) of this string.
*
* <em>WARNING: Because slices observe element order, returning
* big slices of strings with many characters can take a
* considerable amount of time. Avoid running such code in the
* main thread.</em>
*
* @param {int} start
* Position of the Unicode character from where to start slicing.
* @param {int} end
* Position of the first Unicode character that should not be
* included in the slice.
* @return {jsx.string.unicode.WideString}
* @see String.prototype.slice()
*/
slice: function (start, end) {
return new this.constructor(
this.getChars().slice(start, end).join(""));
},
/**
* Returns a substring of this string.
*
* @param {int} start
* Position of the Unicode character from where to start slicing.
* @param {int} length
* Number of Unicode characters in the substring.
* If omitted or <code>undefined</code>, the substring
* contains all characters from <code>start</code>
* to the end of this string.
* @return {jsx.string.unicode.WideString}
* @see #slice()
* @see String.prototype.substr()
*/
substr: function (start, length) {
return this.slice(start,
typeof length == "undefined"
? length
: start + length);
},
/**
* Returns a substring of this string.
*
* @param {int} start
* Position of the Unicode character from where to start slicing.
* @param {int} end (optional)
* Position of the first Unicode character that should not be
* included in the slice. If <code><var>start</var></code>
* is larger than <code><var>end</var></code>, they are swapped.
* @return {jsx.string.unicode.WideString}
* @see String.prototype.substring()
*/
substring: function (start, end) {
if (start > end)
{
var tmp = start;
start = end;
end = tmp;
}
return new this.constructor(
this.getChars().slice(start, end).join(""));
},
/**
* Returns the characters in this object as a primitive
* string value.
*
* @return {string}
*/
toString: function () {
return this.getChars().join("");
},
/**
* @see #toString()
*/
valueOf: function () {
return this.toString();
}
});
/**
* @name length
* @type int
* @memberOf jsx.string.unicode.WideString.prototype
* @see #getLength()
*/
jsx.object.defineProperty(_WideString.prototype, "length", {
"get": function () {
return this.getLength();
}
});
/**
* Returns the <code>string</code> value consisting of the
* characters specified by their code point values.
*
* @function
* @name jsx.string.unicode.WideString.fromCharCode
*/
_WideString.fromCharCode = (function () {
var String_fromCharCode = String.fromCharCode;
/**
* @params {int}
* @return {jsx.string.unicode.WideString}
*/
function _fromCharCode ()
{
var chars = [];
for (var i = 0, len = arguments.length; i < len; ++i)
{
var arg = Math.floor(arguments[i]);
var ch;
if (arg > 0x10FFFF)
{
return jsx.throwThis(jsx.InvalidArgumentError,
["Unsupported Unicode code point value",
"0x" + arg.toString(16).toUpperCase(),
"0..0x10FFFF"]);
}
if (arg > 0xFFFF)
{
var bmpOffset = arg - 0x10000;
var leadSurrogate = 0xD800 + ((bmpOffset >> 10) & 0x3FF);
var trailSurrogate = 0xDC00 + (bmpOffset & 0x3FF);
ch = String_fromCharCode(leadSurrogate, trailSurrogate);
}
else
{
ch = String_fromCharCode(arg);
}
if (_rx_combining.test(ch))
{
chars[chars.length - 1] += ch;
}
else
{
chars.push(ch);
}
}
return new _WideString(chars);
}
return _fromCharCode;
}());
if (jsx.options.augmentBuiltins)
{
if (jsx.options.augmentPrototypes)
{
jsx.object.extend(String.prototype, (function () {
/**
* @type jsx.string.unicode.WideString
*/
var _prevWideString = null;
/**
* Returns the {@link jsx.string.unicode.WideString WideString}
* created from this <code>String</code>.
* <p>
* NOTE: The previously created <code>WideString</code> is
* retained in <code><var>prevWideString</var></code>, which
* increases runtime efficiency with subsequent method calls
* on the same string. Caching <em>all</em> previous values
* would also increase runtime efficiency, but decrease memory
* efficiency at the same time, as unused <code>WideString</code>s
* could not be garbage-collected.<br>
* Calling <code>toString</code> is required so that primitive
* values, not object references, are compared (the latter
* would always be <code>false</code> with internal wrapper
* <code>String</code> objects created from primitive
* string values).
* </p>
* @param {String} s
* @return {jsx.string.unicode.WideString}
*/
function _createWideString (s)
{
return (_prevWideString && _prevWideString.toString() == s
? _prevWideString
: (_prevWideString = new _WideString(s)));
}
return {
/**
* Returns the character in this string
* at the specified position.
* <p>
* Differs from the built-in {@link String.prototype.charAt}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units,
* and that the position may be negative, counting from
* the end of the string.
* </p>
* @memberOf String.prototype
* @param {Number} position
* @return {string}
* @see String.prototype.charAt()
* @see jsx.string.unicode.WideString.prototype.charAt()
*/
charAt: function (position) {
return _createWideString(this).charAt(position);
},
/**
* Returns the Unicode code point value of the character
* in this string at the specified position.
* <p>
* Differs from the built-in {@link String.prototype.charCodeAt}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units,
* and that the position may be negative, counting from
* the end of the string.
* </p>
* @param {Number} position
* @return {number}
* @see String.prototype.charCodeAt()
* @see jsx.string.unicode.WideString.prototype.charCodeAt()
*/
charCodeAt: function (position) {
return _createWideString(this).charCodeAt(position);
},
/**
* Returns the number of Unicode characters in this string.
* <p>
* Differs from the built-in {@link string.length length}
* property in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
* </p>
* @return {number}
* @see string.length
*/
getLength: function () {
return _createWideString(this).getLength();
},
/**
* Returns the index of the first position of a substring
* in this string.
* <p>
* Differs from the built-in {@link String.prototype.indexOf}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
* </p>
* @param {jsx.string.unicode.WideString|String} searchString
* Substring to look for.
* @param {int} position
* Position from where to start searching. The default is
* <code>0</code>.
* @return {number}
* @see String.prototype.indexOf()
*/
indexOf: function (searchString, position) {
return _createWideString(this).indexOf(searchString, position);
},
/**
* Returns the index of the last position of a substring
* in this string.
* <p>
* Differs from the built-in {@link String.prototype.lastIndexOf}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
* </p>
* @param {jsx.string.unicode.WideString|String} searchString
* Substring to look for.
* @param {int} position
* Position from where to start searching backwards.
* The default is the position of the last character.
* @return {number}
* @see String.prototype.lastIndexOf()
*/
lastIndexOf: function (searchString, position) {
return _createWideString(this).lastIndexOf(searchString, position);
},
/**
* Returns a slice (substring) of this string.
* <p>
* Differs from the built-in {@link String.prototype.slice}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
* </p>
* @see String.prototype.slice()
*/
slice: (function () {
var String_prototype_slice = "".slice;
/**
* @param {int} start
* Position of the Unicode character from where to start slicing.
* @param {int} end
* Position of the first Unicode character that should not be
* included in the slice.
* @return {string}
*/
return function (start, end) {
return _rx_wide_string.test(this)
? _createWideString(this).slice(start, end).toString()
: String_prototype_slice.apply(this, arguments);
};
}()),
/**
* Returns a substring of this string.
* <p>
* Differs from the built-in (non-standard)
* {@link String.prototype.substr} method in that it
* considers characters with code points beyond U+FFFF
* that require several UTF-16 code units.
* </p>
* @param {int} start
* Position of the Unicode character from where to start slicing.
* @param {int} length
* Number of Unicode characters in the substring.
* If omitted or <code>undefined</code>, the substring
* contains all characters from <code>start</code>
* to the end of this string.
* @return {string}
* @see String.prototype.substr()
* @see jsx.string.unicode.WideString.prototype.substr()
*/
substr: function (start, length) {
return _createWideString(this).substr(start, length).toString();
},
/**
* Returns a substring of this string.
* <p>
* Differs from the built-in {@link String.prototype.substring}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
* </p>
* @function
* @see String.prototype.substring()
*/
substring: (function () {
var String_prototype_substring = "".substring;
/**
* @param {int} start
* Position of the Unicode character from where to start slicing.
* @param {int} end (optional)
* Position of the first Unicode character that should not be
* included in the slice. If <code><var>start</var></code>
* is larger than <code><var>end</var></code>, they are swapped.
* @return {string}
*/
return function (start, end) {
return _rx_wide_string.test(this)
? _createWideString(this).substring(start, end).toString()
: String_prototype_substring.apply(this, arguments);
};
}())
};
}()), jsx.object.ADD_OVERWRITE);
}
}
if (jsx.options.replaceBuiltins)
{
jsx.object.extend(String, {
/**
* Returns a {@link String} containing the Unicode characters
* specified by the code point arguments.
* <p>
* Differs from the built-in {@link String.fromCharCode}
* method in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
* </p>
* @memberOf String
* @params {Number}
* Code points of the characters from <code>0</code> to
* <code>0x10FFFF</code> inclusive.
* @return {string}
*/
fromCharCode: function () {
return _WideString.fromCharCode.apply(this, arguments).toString();
}
}, jsx.object.ADD_OVERWRITE);
}
return {
/**
* @memberOf jsx.string.unicode
*/
WideString: _WideString
};
}());
/* vim:set fileencoding=utf-8 tabstop=2 shiftwidth=2 softtabstop=2 expandtab: */