]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/node_modules/es6-weak-map/node_modules/es6-iterator/string.js
cdb39ea4e4993186f846a8d61fc2f10dd4f13e3b
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / node_modules / es6-weak-map / node_modules / es6-iterator / string.js
1 // Thanks @mathiasbynens
2 // http://mathiasbynens.be/notes/javascript-unicode#iterating-over-symbols
3
4 'use strict';
5
6 var setPrototypeOf = require('es5-ext/object/set-prototype-of')
7 , d = require('d')
8 , Iterator = require('./')
9
10 , defineProperty = Object.defineProperty
11 , StringIterator;
12
13 StringIterator = module.exports = function (str) {
14 if (!(this instanceof StringIterator)) return new StringIterator(str);
15 str = String(str);
16 Iterator.call(this, str);
17 defineProperty(this, '__length__', d('', str.length));
18
19 };
20 if (setPrototypeOf) setPrototypeOf(StringIterator, Iterator);
21
22 StringIterator.prototype = Object.create(Iterator.prototype, {
23 constructor: d(StringIterator),
24 _next: d(function () {
25 if (!this.__list__) return;
26 if (this.__nextIndex__ < this.__length__) return this.__nextIndex__++;
27 this._unBind();
28 }),
29 _resolve: d(function (i) {
30 var char = this.__list__[i], code;
31 if (this.__nextIndex__ === this.__length__) return char;
32 code = char.charCodeAt(0);
33 if ((code >= 0xD800) && (code <= 0xDBFF)) return char + this.__list__[this.__nextIndex__++];
34 return char;
35 }),
36 toString: d(function () { return '[object String Iterator]'; })
37 });