home *** CD-ROM | disk | FTP | other *** search
- package java.util;
-
- public class StringTokenizer implements Enumeration {
- private int currentPosition;
- private int maxPosition;
- private String str;
- private String delimiters;
- private boolean retTokens;
-
- public StringTokenizer(String str, String delim, boolean returnTokens) {
- this.currentPosition = 0;
- this.str = str;
- this.maxPosition = str.length();
- this.delimiters = delim;
- this.retTokens = returnTokens;
- }
-
- public StringTokenizer(String str, String delim) {
- this(str, delim, false);
- }
-
- public StringTokenizer(String str) {
- this(str, " \t\n\r", false);
- }
-
- private void skipDelimiters() {
- while(!this.retTokens && this.currentPosition < this.maxPosition && this.delimiters.indexOf(this.str.charAt(this.currentPosition)) >= 0) {
- ++this.currentPosition;
- }
-
- }
-
- public boolean hasMoreTokens() {
- this.skipDelimiters();
- return this.currentPosition < this.maxPosition;
- }
-
- public String nextToken() {
- this.skipDelimiters();
- if (this.currentPosition >= this.maxPosition) {
- throw new NoSuchElementException();
- } else {
- int start;
- for(start = this.currentPosition; this.currentPosition < this.maxPosition && this.delimiters.indexOf(this.str.charAt(this.currentPosition)) < 0; ++this.currentPosition) {
- }
-
- if (this.retTokens && start == this.currentPosition && this.delimiters.indexOf(this.str.charAt(this.currentPosition)) >= 0) {
- ++this.currentPosition;
- }
-
- return this.str.substring(start, this.currentPosition);
- }
- }
-
- public String nextToken(String delim) {
- this.delimiters = delim;
- return this.nextToken();
- }
-
- public boolean hasMoreElements() {
- return this.hasMoreTokens();
- }
-
- public Object nextElement() {
- return this.nextToken();
- }
-
- public int countTokens() {
- int count = 0;
-
- for(int currpos = this.currentPosition; currpos < this.maxPosition; ++count) {
- while(!this.retTokens && currpos < this.maxPosition && this.delimiters.indexOf(this.str.charAt(currpos)) >= 0) {
- ++currpos;
- }
-
- if (currpos >= this.maxPosition) {
- break;
- }
-
- int start;
- for(start = currpos; currpos < this.maxPosition && this.delimiters.indexOf(this.str.charAt(currpos)) < 0; ++currpos) {
- }
-
- if (this.retTokens && start == currpos && this.delimiters.indexOf(this.str.charAt(currpos)) >= 0) {
- ++currpos;
- }
- }
-
- return count;
- }
- }
-