AnotherStringTokenizer.java revision 2
aa8d013ec5b09cd1cd904173d6234ef126eb2126Peter Simons// The MIT License
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano//
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// Copyright (c) 2004 Evren Sirin
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano//
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// Permission is hereby granted, free of charge, to any person obtaining a copy
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// of this software and associated documentation files (the "Software"), to
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// deal in the Software without restriction, including without limitation the
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// sell copies of the Software, and to permit persons to whom the Software is
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// furnished to do so, subject to the following conditions:
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano//
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// The above copyright notice and this permission notice shall be included in
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// all copies or substantial portions of the Software.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano//
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano// IN THE SOFTWARE.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcanopackage org.mindswap.utils;
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcanopublic class AnotherStringTokenizer {
aa8d013ec5b09cd1cd904173d6234ef126eb2126Peter Simons String str;
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand String delim;
10fba81b9d0221b8e47aa1e0b43236413b7d28dfMichel Normand int start = 0;
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand int stop = -1;
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano public AnotherStringTokenizer(String s) {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano this(s, " ");
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano }
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano public AnotherStringTokenizer(String s, String d) {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano str = s;
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano delim = d;
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano }
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano public String nextToken() {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return nextToken(delim);
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano }
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano public String nextToken(String delim) {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano String ret = null;
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano if(str == null)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano System.out.println("what");
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano stop = str.indexOf(delim, start);
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano if(stop != -1) {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano ret = str.substring(start, stop);
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen start = stop + delim.length();
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen if(start > str.length())
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen start = str.length() - 1;
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen }
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen return ret;
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano }
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano}
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano