📄 tokenizer.java
字号:
package com.libGPS4j2me.devices.StdGPS.parser;
import java.util.NoSuchElementException;
/**
* Tokenizer used in Parser.
*
* @author Dominik Schmidt
*/
public class Tokenizer {
/**
* Delimiter string.
*/
private static final String DELIMITER = ",";
private int currentPosition;
private int nextPosition;
private String s;
/**
* Constructs a new tokenizer for the given string.
*
* @param s String to be tokenized
*/
public Tokenizer(String s) {
this.s = s;
this.currentPosition = 0;
this.nextPosition = s.indexOf(DELIMITER, currentPosition);
}
/**
* @return True, if there is a token left
*/
public boolean hasNext() {
return nextPosition != -1 && currentPosition <= nextPosition;
}
/**
*
* @return Next token
* @throws NoSuchElementException If there is no token left
*/
public String next() throws NoSuchElementException {
if (!hasNext())
throw new NoSuchElementException();
String next = s.substring(currentPosition, nextPosition);
currentPosition = nextPosition + 1;
nextPosition = s.indexOf(DELIMITER, currentPosition);
return next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -