garydgregory commented on code in PR #502:
URL: https://github.com/apache/commons-csv/pull/502#discussion_r1898490278


##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -701,6 +701,77 @@ public void testGetHeaderComment_NoComment3() throws 
IOException {
         }
     }
 
+    @Test
+    public void testGetRecordThreeBytesRead() throws Exception {
+        final String code = "id,date,val5,val4\n" +
+            "11111111111111,'4017-09-01',きちんと節分近くには咲いてる~,v4\n" +
+            "22222222222222,'4017-01-01',おはよう私の友人~,v4\n" +
+            "33333333333333,'4017-01-01',きる自然の力ってすごいな~,v4\n";
+        final CSVFormat format = CSVFormat.Builder.create()
+            .setDelimiter(',')
+            .setQuote('\'')
+            .get();
+        try (CSVParser parser = CSVParser.builder().setReader(new 
StringReader(code)).setFormat(format).setCharset(UTF_8).setEnableByteTracking(true).get()
 ) {
+            CSVRecord record = new CSVRecord(parser, null, null, 1L, 0L, 0L);

Review Comment:
   Use final where you can.



##########
src/test/java/org/apache/commons/csv/CSVParserTest.java:
##########
@@ -701,6 +701,77 @@ public void testGetHeaderComment_NoComment3() throws 
IOException {
         }
     }
 
+    @Test
+    public void testGetRecordThreeBytesRead() throws Exception {
+        final String code = "id,date,val5,val4\n" +
+            "11111111111111,'4017-09-01',きちんと節分近くには咲いてる~,v4\n" +
+            "22222222222222,'4017-01-01',おはよう私の友人~,v4\n" +
+            "33333333333333,'4017-01-01',きる自然の力ってすごいな~,v4\n";
+        final CSVFormat format = CSVFormat.Builder.create()
+            .setDelimiter(',')
+            .setQuote('\'')
+            .get();
+        try (CSVParser parser = CSVParser.builder().setReader(new 
StringReader(code)).setFormat(format).setCharset(UTF_8).setEnableByteTracking(true).get()
 ) {
+            CSVRecord record = new CSVRecord(parser, null, null, 1L, 0L, 0L);
+
+            assertEquals(0, parser.getRecordNumber());
+            assertNotNull(record = parser.nextRecord());
+            assertEquals(1, record.getRecordNumber());
+            assertEquals(code.indexOf('i'), record.getCharacterPosition());
+            assertEquals(record.getBytePosition(), 
record.getCharacterPosition());
+
+            assertNotNull(record = parser.nextRecord());
+            assertEquals(2, record.getRecordNumber());
+            assertEquals(code.indexOf('1'), record.getCharacterPosition());
+            assertEquals(record.getBytePosition(), 
record.getCharacterPosition());
+
+            assertNotNull(record = parser.nextRecord());
+            assertEquals(3, record.getRecordNumber());
+            assertEquals(code.indexOf('2'), record.getCharacterPosition());
+            assertEquals(record.getBytePosition(), 95);
+
+            assertNotNull(record = parser.nextRecord());
+            assertEquals(4, record.getRecordNumber());
+            assertEquals(code.indexOf('3'), record.getCharacterPosition());
+            assertEquals(record.getBytePosition(), 154);
+        };
+
+    }
+
+    @Test
+    public void testGetRecordFourBytesRead() throws Exception {
+        final String code = "id,a,b,c\n" +
+            "1,😊,🤔,😂\n" +
+            "2,😊,🤔,😂\n" +
+            "3,😊,🤔,😂\n";
+        final CSVFormat format = CSVFormat.Builder.create()
+            .setDelimiter(',')
+            .setQuote('\'')
+            .get();
+        try (CSVParser parser = CSVParser.builder().setReader(new 
StringReader(code)).setFormat(format).setCharset(UTF_8).setEnableByteTracking(true).get())
 {
+            CSVRecord record = new CSVRecord(parser, null, null, 1L, 0L, 0L);

Review Comment:
   Use final where you can.



##########
src/main/java/org/apache/commons/csv/CSVRecord.java:
##########
@@ -144,6 +159,15 @@ public long getCharacterPosition() {
         return characterPosition;
     }
 
+    /**
+     * Returns the start byte of this record as a character byte in the source 
stream.
+     *
+     * @return the start byte of this record as a character byte in the source 
stream.

Review Comment:
   New public and protected elements should have a Javadoc tag of @since 1.13.0.
   Please clarify the comment:  Specifically document this data as "position".



##########
src/main/java/org/apache/commons/csv/CSVRecord.java:
##########
@@ -48,6 +48,11 @@ public final class CSVRecord implements Serializable, 
Iterable<String> {
      */
     private final long characterPosition;
 
+    /**
+     * The start byte of this record as a character byte in the source stream.

Review Comment:
   Please update the comment to clarify.



##########
src/main/java/org/apache/commons/csv/CSVParser.java:
##########
@@ -200,6 +201,17 @@ public Builder setRecordNumber(final long recordNumber) {
             return asThis();
         }
 
+        /**
+         * Sets whether to enable byte tracking for the parser.
+         *
+         * @param enableByteTracking {@code true} to enable byte tracking; 
{@code false} to disable it.
+         * @return this instance.
+         */

Review Comment:
   New public and protected elements should have a Javadoc tag of @since 1.13.0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to