Debian Codegraph @

rhino/src/org/mozilla/javascript/NativeStringIterator.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 package org.mozilla.javascript;
8
9 public final class NativeStringIterator extends ES6Iterator {
10 private static final long serialVersionUID = 1L;
11 private static final String ITERATOR_TAG = "StringIterator";
12
13 static void init(ScriptableObject scope, boolean sealed) {
14 ES6Iterator.init(scope, sealed, new NativeStringIterator(), ITERATOR_TAG);
15 }
16
17 /**
18 * Only for constructing the prototype object.
19 */
20 private NativeStringIterator() {
21 super();
22 }
23
24 NativeStringIterator(Scriptable scope, Scriptable stringLike) {
25 super(scope);
26 this.index = 0;
27 this.string = ScriptRuntime.toString(stringLike);
28 }
29
30 @Override
31 public String getClassName() {
32 return "String Iterator";
33 }
34
35 @Override
36 protected boolean isDone(Context cx, Scriptable scope) {
37 return index >= string.length();
38 }
39
40 @Override
41 protected Object nextValue(Context cx, Scriptable scope) {
42 int newIndex = string.offsetByCodePoints(index, 1);
43 Object value = string.substring(index, newIndex);
44 index = newIndex;
45 return value;
46 }
47
48 @Override
49 protected String getTag() {
50 return ITERATOR_TAG;
51 }
52
53 private String string;
54 private int index;
55 }