|
@@ -7,24 +7,24 @@ |
7 |
7 |
|
private String mSource; |
8 |
8 |
|
private int mFrom, mTo; |
9 |
9 |
|
|
10 |
|
- |
public CharSource(String pSource, int pFrom) { |
11 |
|
- |
mSource = StringUtils.deNull(pSource); |
12 |
|
- |
if ((mFrom = pFrom) < 0) { |
13 |
|
- |
throw new IllegalArgumentException("'From' not allowed to be negative"); |
|
10 |
+ |
public CharSource( String pSource, int pFrom ) { |
|
11 |
+ |
mSource = StringUtils.deNull( pSource ); |
|
12 |
+ |
if ( (mFrom = pFrom) < 0 ) { |
|
13 |
+ |
throw new IllegalArgumentException( "'From' not allowed to be negative" ); |
14 |
14 |
|
} |
15 |
15 |
|
mTo = mSource.length(); |
16 |
16 |
|
} |
17 |
17 |
|
|
18 |
|
- |
public CharSource(String pSource) { |
19 |
|
- |
this(pSource, 0); |
|
18 |
+ |
public CharSource( String pSource ) { |
|
19 |
+ |
this( pSource, 0 ); |
20 |
20 |
|
} |
21 |
21 |
|
|
22 |
|
- |
public CharSource(String pSource, int pFrom, int pTo) { |
23 |
|
- |
this(pSource, pFrom); |
24 |
|
- |
if (pTo > mTo) { |
25 |
|
- |
throw new IllegalArgumentException("'To' not allowed to be greater than the length of the 'Source' string"); |
|
22 |
+ |
public CharSource( String pSource, int pFrom, int pTo ) { |
|
23 |
+ |
this( pSource, pFrom ); |
|
24 |
+ |
if ( pTo > mTo ) { |
|
25 |
+ |
throw new IllegalArgumentException( "'To' not allowed to be greater than the length of the 'Source' string" ); |
26 |
26 |
|
} |
27 |
|
- |
if (pTo < 0) { |
|
27 |
+ |
if ( pTo < 0 ) { |
28 |
28 |
|
mTo += pTo; |
29 |
29 |
|
} else { |
30 |
30 |
|
mTo = pTo; |
|
@@ -36,50 +36,50 @@ |
36 |
36 |
|
} |
37 |
37 |
|
|
38 |
38 |
|
public int peek() { |
39 |
|
- |
return anyRemaining() ? mSource.charAt(mFrom) : -1; |
|
39 |
+ |
return anyRemaining() ? mSource.charAt( mFrom ) : -1; |
40 |
40 |
|
} |
41 |
41 |
|
|
42 |
42 |
|
public int get() { |
43 |
|
- |
return anyRemaining() ? mSource.charAt(mFrom++) : -1; |
|
43 |
+ |
return anyRemaining() ? mSource.charAt( mFrom++ ) : -1; |
44 |
44 |
|
} |
45 |
45 |
|
|
46 |
46 |
|
public char getRequired() { |
47 |
|
- |
if (anyRemaining()) { |
48 |
|
- |
return mSource.charAt(mFrom++); |
|
47 |
+ |
if ( anyRemaining() ) { |
|
48 |
+ |
return mSource.charAt( mFrom++ ); |
49 |
49 |
|
} |
50 |
|
- |
throw new IllegalArgumentException("Unexpected EOD encountered at index " + mFrom + " in " + mSource); |
|
50 |
+ |
throw new IllegalArgumentException( "Unexpected EOD encountered at index " + mFrom + " in " + mSource ); |
51 |
51 |
|
} |
52 |
52 |
|
|
53 |
|
- |
public String getUpTo(char c) { |
54 |
|
- |
int at = mSource.indexOf(c, mFrom); |
55 |
|
- |
if (at == -1) { |
|
53 |
+ |
public String getUpTo( char c ) { |
|
54 |
+ |
int at = mSource.indexOf( c, mFrom ); |
|
55 |
+ |
if ( at == -1 ) { |
56 |
56 |
|
return ""; |
57 |
57 |
|
} |
58 |
|
- |
String rv = mSource.substring(mFrom, at); |
|
58 |
+ |
String rv = mSource.substring( mFrom, at ); |
59 |
59 |
|
mFrom = at; |
60 |
60 |
|
return rv; |
61 |
61 |
|
} |
62 |
62 |
|
|
63 |
63 |
|
public boolean consumeSpaces() { |
64 |
|
- |
while (peek() == ' ') { |
|
64 |
+ |
while ( peek() == ' ' ) { |
65 |
65 |
|
mFrom++; |
66 |
66 |
|
} |
67 |
67 |
|
return anyRemaining(); |
68 |
68 |
|
} |
69 |
69 |
|
|
70 |
70 |
|
public String getUpToNonVisible7BitAscii() { |
71 |
|
- |
if (!anyRemaining()) { |
|
71 |
+ |
if ( !anyRemaining() ) { |
72 |
72 |
|
return ""; |
73 |
73 |
|
} |
74 |
74 |
|
int zFrom = mFrom; |
75 |
|
- |
for (int c = peek(); (c != -1) && ((' ' < c) && (c <= 126)); c = peek()) { |
|
75 |
+ |
for ( int c = peek(); (c != -1) && ((' ' < c) && (c <= 126)); c = peek() ) { |
76 |
76 |
|
mFrom++; |
77 |
77 |
|
} |
78 |
|
- |
return mSource.substring(zFrom, mFrom); |
|
78 |
+ |
return mSource.substring( zFrom, mFrom ); |
79 |
79 |
|
} |
80 |
80 |
|
|
81 |
81 |
|
public boolean consumeNonVisible7BitAscii() { |
82 |
|
- |
for (int c = peek(); (c != -1) && ((c <= ' ') || (126 < c)); c = peek()) { |
|
82 |
+ |
for ( int c = peek(); (c != -1) && ((c <= ' ') || (126 < c)); c = peek() ) { |
83 |
83 |
|
mFrom++; |
84 |
84 |
|
} |
85 |
85 |
|
return anyRemaining(); |
|
@@ -95,6 +95,6 @@ |
95 |
95 |
|
|
96 |
96 |
|
@Override |
97 |
97 |
|
public String toString() { |
98 |
|
- |
return mSource.substring(mFrom, mTo); |
|
98 |
+ |
return mSource.substring( mFrom, mTo ); |
99 |
99 |
|
} |
100 |
100 |
|
} |