📄 stringtokenizer.java
字号:
/************************************************************************This file is part of java core libraries for the simpleRTJ virtual machine.This file is covered by the GNU GPL with the following exception: As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGESOR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Created/modified by: RTJ Computing***********************************************************************/package java.util;import java.lang.*;public class StringTokenizer implements Enumeration{ private String input; private String delims; private boolean retDelim; private int position; public StringTokenizer(String str) { this (str, " \t\n\r\f"); } public StringTokenizer(String str, String delim) { this (str, delim, false); } public StringTokenizer(String input, String delims, boolean retDelim) { this.input = input; this.delims = delims; this.retDelim = retDelim; position = 0; } public int countTokens() { int count = 0; int curPos = position; while (nextTokenInternal(false) != null) count++; position = curPos; return count; } public boolean hasMoreElements() { return hasMoreTokens(); } public boolean hasMoreTokens() { int oldPosition = position; String ret = nextTokenInternal(false); position = oldPosition; if (ret == null) return false; return true; } public Object nextElement() { return (Object)nextToken(); } public String nextToken(String delims) { this.delims = delims; return nextToken(); } public String nextToken() { String ret = nextTokenInternal(true); if (ret == null) throw new NoSuchElementException("no more elements"); return ret; } private String nextTokenInternal(boolean retStr) { if (position >= input.length()) return null; if (delims.indexOf(input.charAt(position)) != -1) { position++; if (retDelim) { if (retStr) return input.substring(position-1, position); return input; } while (true) { if (position >= input.length()) return null; if (delims.indexOf(input.charAt(position)) == -1) break; position++; } } int start = position; while (true) { position++; if (position >= input.length() || delims.indexOf(input.charAt(position)) != -1) break; } if (retStr) return input.substring(start, position); return input; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -