1 |
|
2 |
|
3 |
|
4 | "use strict";
|
5 |
|
6 | var setPrototypeOf = require("es5-ext/object/set-prototype-of")
|
7 | , d = require("d")
|
8 | , Symbol = require("es6-symbol")
|
9 | , Iterator = require("./");
|
10 |
|
11 | var defineProperty = Object.defineProperty, StringIterator;
|
12 |
|
13 | StringIterator = module.exports = function (str) {
|
14 | if (!(this instanceof StringIterator)) throw new TypeError("Constructor requires 'new'");
|
15 | str = String(str);
|
16 | Iterator.call(this, str);
|
17 | defineProperty(this, "__length__", d("", str.length));
|
18 | };
|
19 | if (setPrototypeOf) setPrototypeOf(StringIterator, Iterator);
|
20 |
|
21 |
|
22 | delete StringIterator.prototype.constructor;
|
23 |
|
24 | StringIterator.prototype = Object.create(Iterator.prototype, {
|
25 | _next: d(function () {
|
26 | if (!this.__list__) return undefined;
|
27 | if (this.__nextIndex__ < this.__length__) return this.__nextIndex__++;
|
28 | this._unBind();
|
29 | return undefined;
|
30 | }),
|
31 | _resolve: d(function (i) {
|
32 | var char = this.__list__[i], code;
|
33 | if (this.__nextIndex__ === this.__length__) return char;
|
34 | code = char.charCodeAt(0);
|
35 | if (code >= 0xd800 && code <= 0xdbff) return char + this.__list__[this.__nextIndex__++];
|
36 | return char;
|
37 | })
|
38 | });
|
39 | defineProperty(StringIterator.prototype, Symbol.toStringTag, d("c", "String Iterator"));
|