0N/A/*
1042N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
553N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
553N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A/*
0N/A *******************************************************************************
0N/A * Copyright (C) 2009, International Business Machines Corporation and *
0N/A * others. All Rights Reserved. *
0N/A *******************************************************************************
0N/A */
0N/Apackage sun.util.locale;
0N/A
0N/Apublic class StringTokenIterator {
0N/A private String text;
0N/A private String dlms; // null if a single char delimiter
0N/A private char delimiterChar; // delimiter if a single char delimiter
0N/A
0N/A private String token;
0N/A private int start;
0N/A private int end;
0N/A private boolean done;
0N/A
0N/A public StringTokenIterator(String text, String dlms) {
0N/A this.text = text;
0N/A if (dlms.length() == 1) {
0N/A delimiterChar = dlms.charAt(0);
0N/A } else {
0N/A this.dlms = dlms;
0N/A }
0N/A setStart(0);
0N/A }
0N/A
0N/A public String first() {
0N/A setStart(0);
0N/A return token;
0N/A }
0N/A
0N/A public String current() {
0N/A return token;
0N/A }
0N/A
0N/A public int currentStart() {
0N/A return start;
0N/A }
0N/A
0N/A public int currentEnd() {
0N/A return end;
0N/A }
0N/A
0N/A public boolean isDone() {
0N/A return done;
0N/A }
0N/A
0N/A public String next() {
0N/A if (hasNext()) {
0N/A start = end + 1;
0N/A end = nextDelimiter(start);
0N/A token = text.substring(start, end);
0N/A } else {
0N/A start = end;
0N/A token = null;
0N/A done = true;
0N/A }
0N/A return token;
0N/A }
0N/A
0N/A public boolean hasNext() {
0N/A return (end < text.length());
0N/A }
0N/A
0N/A public StringTokenIterator setStart(int offset) {
0N/A if (offset > text.length()) {
0N/A throw new IndexOutOfBoundsException();
0N/A }
0N/A start = offset;
0N/A end = nextDelimiter(start);
0N/A token = text.substring(start, end);
0N/A done = false;
0N/A return this;
0N/A }
0N/A
0N/A public StringTokenIterator setText(String text) {
0N/A this.text = text;
0N/A setStart(0);
0N/A return this;
0N/A }
0N/A
0N/A private int nextDelimiter(int start) {
0N/A int textlen = this.text.length();
0N/A if (dlms == null) {
0N/A for (int idx = start; idx < textlen; idx++) {
0N/A if (text.charAt(idx) == delimiterChar) {
0N/A return idx;
0N/A }
0N/A }
0N/A } else {
0N/A int dlmslen = dlms.length();
0N/A for (int idx = start; idx < textlen; idx++) {
0N/A char c = text.charAt(idx);
0N/A for (int i = 0; i < dlmslen; i++) {
0N/A if (c == dlms.charAt(i)) {
0N/A return idx;
0N/A }
0N/A }
0N/A }
0N/A }
388N/A return textlen;
388N/A }
388N/A}
388N/A