add solution for hw6:3233
This commit is contained in:
@@ -7,6 +7,7 @@ public class WordScanner {
|
||||
private BufferedReader br;
|
||||
private String line = null;
|
||||
private int pos = 0;
|
||||
private int lineNumber = 0;
|
||||
|
||||
public WordScanner(String fileName) throws IOException {
|
||||
br = new BufferedReader(new InputStreamReader(
|
||||
@@ -16,14 +17,17 @@ public class WordScanner {
|
||||
private boolean hasNextLine() throws IOException {
|
||||
if (line != null && pos < line.length()) return true;
|
||||
line = br.readLine();
|
||||
if (line != null) {
|
||||
lineNumber++;
|
||||
}
|
||||
pos = 0;
|
||||
return line != null;
|
||||
}
|
||||
|
||||
private boolean isWordChar(char c) {
|
||||
return Character.isLetter(c) || c == '\'' ||
|
||||
Character.getType(c) == Character.DASH_PUNCTUATION ||
|
||||
c == '$' || c == '_';
|
||||
return Character.isLetter(c) || Character.isDigit(c) ||
|
||||
c == '\'' || c == '$' || c == '_' ||
|
||||
Character.getType(c) == Character.DASH_PUNCTUATION;
|
||||
}
|
||||
|
||||
public boolean hasNextWord() throws IOException {
|
||||
@@ -51,7 +55,20 @@ public class WordScanner {
|
||||
return line.substring(start, pos).toLowerCase();
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
br.close();
|
||||
}
|
||||
|
||||
public void reset(String fileName) throws IOException {
|
||||
br.close();
|
||||
br = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream(fileName), StandardCharsets.UTF_8));
|
||||
line = null;
|
||||
pos = 0;
|
||||
lineNumber = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user