This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-csv.git
commit 6711054af0ea9f6330bdec25687f0a1f9b9212aa Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Wed Jan 8 06:42:02 2025 -0500 Add Checstyle FinalParameters --- src/conf/checkstyle/checkstyle.xml | 1 + src/main/java/org/apache/commons/csv/Lexer.java | 30 +++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/conf/checkstyle/checkstyle.xml b/src/conf/checkstyle/checkstyle.xml index 009935a6..e2a1720b 100644 --- a/src/conf/checkstyle/checkstyle.xml +++ b/src/conf/checkstyle/checkstyle.xml @@ -43,6 +43,7 @@ limitations under the License. <module name="TreeWalker"> <module name="AvoidStarImport" /> <module name="FinalLocalVariable" /> + <module name="FinalParameters" /> <module name="IllegalImport" /> <module name="ImportOrder"> <property name="option" value="top" /> diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java index 2e9e7137..0e5f3686 100644 --- a/src/main/java/org/apache/commons/csv/Lexer.java +++ b/src/main/java/org/apache/commons/csv/Lexer.java @@ -402,34 +402,35 @@ final class Lexer implements Closeable { * </ul> * * @param token the current token - * @param ch the current character + * @param ch the current character * @return the filled token * @throws IOException on stream access error * @throws CSVException Thrown on invalid input. */ - private Token parseSimpleToken(final Token token, int ch) throws IOException { + private Token parseSimpleToken(final Token token, final int ch) throws IOException { // Faster to use while(true)+break than while(token.type == INVALID) + int cur = ch; while (true) { - if (readEndOfLine(ch)) { + if (readEndOfLine(cur)) { token.type = Token.Type.EORECORD; break; } - if (isEndOfFile(ch)) { + if (isEndOfFile(cur)) { token.type = Token.Type.EOF; token.isReady = true; // There is data at EOF break; } - if (isDelimiter(ch)) { + if (isDelimiter(cur)) { token.type = Token.Type.TOKEN; break; } // continue - if (isEscape(ch)) { + if (isEscape(cur)) { appendNextEscapedCharacterToToken(token); } else { - token.content.append((char) ch); + token.content.append((char) cur); } - ch = reader.read(); // continue + cur = reader.read(); // continue } if (ignoreSurroundingSpaces) { @@ -444,11 +445,12 @@ final class Lexer implements Closeable { * * @return true if the given or next character is a line-terminator */ - boolean readEndOfLine(int ch) throws IOException { + boolean readEndOfLine(final int ch) throws IOException { // check if we have \r\n... - if (ch == Constants.CR && reader.peek() == Constants.LF) { + int cur = ch; + if (cur == Constants.CR && reader.peek() == Constants.LF) { // note: does not change ch outside of this method! - ch = reader.read(); + cur = reader.read(); // Save the EOL state if (firstEol == null) { this.firstEol = Constants.CRLF; @@ -456,14 +458,14 @@ final class Lexer implements Closeable { } // save EOL state here. if (firstEol == null) { - if (ch == Constants.LF) { + if (cur == Constants.LF) { this.firstEol = LF_STRING; - } else if (ch == Constants.CR) { + } else if (cur == Constants.CR) { this.firstEol = CR_STRING; } } - return ch == Constants.LF || ch == Constants.CR; + return cur == Constants.LF || cur == Constants.CR; } // TODO escape handling needs more work