Skip to content

Commit 9a27bb5

Browse files
committed
Refactor magic strings into constants.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1397536 13f79535-47bb-0310-9956-ffa450edef68
1 parent 66a56ee commit 9a27bb5

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/main/java/org/apache/commons/csv/Lexer.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
*/
2525
abstract class Lexer {
2626

27+
private static final char FF = '\f';
28+
private static final char BELL = '\b';
29+
private static final char TAB = '\t';
30+
private static final char LF = '\n';
31+
private static final char CR = '\r';
32+
2733
private final boolean isEncapsulating;
2834
private final boolean isEscaping;
2935
private final boolean isCommentEnabled;
@@ -65,15 +71,15 @@ int readEscape() throws IOException {
6571
final int c = in.read();
6672
switch (c) {
6773
case 'r':
68-
return '\r';
74+
return CR;
6975
case 'n':
70-
return '\n';
76+
return LF;
7177
case 't':
72-
return '\t';
78+
return TAB;
7379
case 'b':
74-
return '\b';
80+
return BELL;
7581
case 'f':
76-
return '\f';
82+
return FF;
7783
case ExtendedBufferedReader.END_OF_STREAM:
7884
throw new IOException("EOF whilst processing escape sequence");
7985
default:
@@ -105,11 +111,11 @@ boolean isWhitespace(final int c) {
105111
*/
106112
boolean isEndOfLine(int c) throws IOException {
107113
// check if we have \r\n...
108-
if (c == '\r' && in.lookAhead() == '\n') {
114+
if (c == CR && in.lookAhead() == LF) {
109115
// note: does not change c outside of this method !!
110116
c = in.read();
111117
}
112-
return c == '\n' || c == '\r';
118+
return c == LF || c == CR;
113119
}
114120

115121
/**
@@ -119,7 +125,7 @@ boolean isEndOfLine(int c) throws IOException {
119125
* @return true if the character is at the start of a line.
120126
*/
121127
boolean isStartOfLine(final int c) {
122-
return c == '\n' || c == '\r' || c == ExtendedBufferedReader.UNDEFINED;
128+
return c == LF || c == CR || c == ExtendedBufferedReader.UNDEFINED;
123129
}
124130

125131
/**

0 commit comments

Comments
 (0)