1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var createIteratorConstructor = require('../internals/iterator-create-constructor');
|
4 | var createIterResultObject = require('../internals/create-iter-result-object');
|
5 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
6 | var toString = require('../internals/to-string');
|
7 | var InternalStateModule = require('../internals/internal-state');
|
8 | var StringMultibyteModule = require('../internals/string-multibyte');
|
9 |
|
10 | var codeAt = StringMultibyteModule.codeAt;
|
11 | var charAt = StringMultibyteModule.charAt;
|
12 | var STRING_ITERATOR = 'String Iterator';
|
13 | var setInternalState = InternalStateModule.set;
|
14 | var getInternalState = InternalStateModule.getterFor(STRING_ITERATOR);
|
15 |
|
16 |
|
17 | var $StringIterator = createIteratorConstructor(function StringIterator(string) {
|
18 | setInternalState(this, {
|
19 | type: STRING_ITERATOR,
|
20 | string: string,
|
21 | index: 0
|
22 | });
|
23 | }, 'String', function next() {
|
24 | var state = getInternalState(this);
|
25 | var string = state.string;
|
26 | var index = state.index;
|
27 | var point;
|
28 | if (index >= string.length) return createIterResultObject(undefined, true);
|
29 | point = charAt(string, index);
|
30 | state.index += point.length;
|
31 | return createIterResultObject({ codePoint: codeAt(point, 0), position: index }, false);
|
32 | });
|
33 |
|
34 |
|
35 |
|
36 | $({ target: 'String', proto: true, forced: true }, {
|
37 | codePoints: function codePoints() {
|
38 | return new $StringIterator(toString(requireObjectCoercible(this)));
|
39 | }
|
40 | });
|