// Job: Jay's Own Browser, a web browser written in Java by Jay Skeer // Copyright (C) 1996 Jay Skeer, Jay Prime Positive // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // import PushBackStringTokenizer; public class myPushBackStringTokenizer { String unread_token= null; int read_position= 0; int to_tokenize_len= 0; char to_tokenize[]= null; String delimiters= null; boolean return_delims= false; public myPushBackStringTokenizer (String totok, String delims, boolean return_delims_p) { unread_token= null; read_position= 0; if (null != totok) { to_tokenize_len= totok.length(); to_tokenize= new char[to_tokenize_len]; totok.getChars(0, to_tokenize_len, to_tokenize, 0); } else { to_tokenize_len= 0; to_tokenize= null; } delimiters= delims; return_delims= return_delims_p; } private boolean has_more_chars() { return (read_position < to_tokenize_len); } private char peek_char() { return (to_tokenize[read_position]); } private char next_char() { return (to_tokenize[read_position++]); } private boolean is_delim(char c) { return (0 <= delimiters.indexOf(c)); } private void unread_token(String t) { unread_token= t; } public void unreadToken(String t) { unread_token(t); } private String next_token() { String rv= null; //Jdb.enter("MPST.next_token()"); if (null != unread_token) { //Jdb.trace("re-read unread token"); rv= unread_token; unread_token= null; } else if (this.has_more_chars()) { if (return_delims && is_delim(peek_char())) { rv= (new Character(next_char())).toString(); //Jdb.trace("return delim token"); } else { while ((this.has_more_chars()) && (is_delim(peek_char()))) { //Jdb.trace("skip delim token(s)"); next_char(); } rv= new String(); while ((this.has_more_chars()) && (! is_delim(peek_char()))) { rv= rv + next_char(); } //Jdb.trace("return non-delim token"); } } //Jdb.exit("MPST.next_token() => " + rv); return rv; } public String nextToken() { return next_token(); } private String peek_token() { String rv= null; if (null != unread_token) { rv= unread_token; } else { rv= next_token(); unread_token(rv); } return rv; } public String peekToken() { return peek_token(); } public boolean hasMoreTokens() { boolean rv= false; if (null != unread_token) { rv= true; } else { String s= peek_token(); if (null != s) { rv= true; } } return rv; } }