MCPcopy Create free account
hub / github.com/ReadyTalk/avian / StringTokenizer

Class StringTokenizer

classpath/java/util/StringTokenizer.java:13–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11package java.util;
12
13public class StringTokenizer implements Enumeration {
14 private final String in;
15 private String delimiters;
16 private final boolean includeDelimiters;
17 private int position;
18
19 public StringTokenizer(String in, String delimiters,
20 boolean includeDelimiters)
21 {
22 this.in = in;
23 this.delimiters = delimiters;
24 this.includeDelimiters = includeDelimiters;
25 }
26
27 public StringTokenizer(String in, String delimiters) {
28 this(in, delimiters, false);
29 }
30
31 public StringTokenizer(String in) {
32 this(in, " \t\r\n\f");
33 }
34
35 private boolean isDelimiter(char c) {
36 return delimiters.indexOf(c) >= 0;
37 }
38
39 public int countTokens() {
40 int count = 0;
41 boolean sawNonDelimiter = false;
42 for (int i = position; i < in.length(); ++i) {
43 if (isDelimiter(in.charAt(i))) {
44 if (sawNonDelimiter) {
45 sawNonDelimiter = false;
46 ++ count;
47 }
48
49 if (includeDelimiters) {
50 ++ count;
51 }
52 } else {
53 sawNonDelimiter = true;
54 }
55 }
56
57 if (sawNonDelimiter) {
58 ++ count;
59 }
60
61 return count;
62 }
63
64 public boolean hasMoreTokens() {
65 for (int i = position; i < in.length(); ++i) {
66 if (isDelimiter(in.charAt(i))) {
67 if (includeDelimiters) {
68 return true;
69 }
70 } else {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected