From ba016bd7597e97eb4745cf71b423ce262f208879 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Tue, 26 Mar 2013 16:36:58 +0000 Subject: [PATCH] Javadoc. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1461213 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/csv/CSVParser.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 7be97b33..966edd02 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -36,28 +36,40 @@ import java.util.NoSuchElementException; * specification of a {@link CSVFormat}. * *

- * Parsing of a csv-string having tabs as separators, '"' as an optional value encapsulator, and comments starting with - * '#': + * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, + * and comments starting with '#', you write: *

* *
- * CSVFormat format = new CSVFormat('\t', '"', '#');
  * Reader in = new StringReader("a\tb\nc\td");
- * List<CSVRecord> records = new CSVParser(in, format).getRecords();
+ * Iterable<CSVRecord> parser = CSVFormat.newBuilder()
+ *     .withCommentStart('#')
+ *     .withDelimiter('\t')
+ *     .withQuoteChar('"').parse(in);
+ *  for (CSVRecord csvRecord : parse) {
+ *     ...
+ *  }
  * 
* *

- * Parsing of a csv-string in Excel CSV format, using a for-each loop: + * To parse CSV input in a given format like Excel, you write: *

* *
  * Reader in = new StringReader("a;b\nc;d");
- * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
+ * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in);
  * for (CSVRecord record : parser) {
  *     ...
  * }
  * 
- * + *

+ * You may also get a List of records: + *

+ *
+ * Reader in = new StringReader("a;b\nc;d");
+ * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
+ * List<CSVRecord> list = parser.getRecords();
+ * 
*

* Internal parser state is completely covered by the format and the reader-state. *