com.darwinsys.csv
Class CSVRE

java.lang.Object
  extended by com.darwinsys.csv.CSVRE

public class CSVRE
extends java.lang.Object

Simple demo of CSV matching using Regular Expressions. Does NOT use the "CSV" class defined in the Java CookBook, but uses a regex pattern simplified from Chapter 7 of Mastering Regular Expressions (p. 205, first edn.) Example usage:

 public static void main(String[] argv) throws IOException {
        System.out.println(CSV_PATTERN);
        new CSVRE().process(new BufferedReader(new InputStreamReader(System.in)));
 }
 

Version:
$Id: CSVRE.java,v 1.21 2006/08/28 20:37:54 ian Exp $

Field Summary
static java.lang.String CSV_PATTERN
          The rather involved pattern used to match CSV's consists of three alternations: the first matches a quoted field, the second unquoted, the third a null field.
 
Constructor Summary
CSVRE()
          Construct a regex-based CSV parser.
 
Method Summary
static void main(java.lang.String[] argv)
           
 java.util.List<java.lang.String> parse(java.lang.String line)
          Parse one line.
 void process(java.io.BufferedReader in)
          Process one file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CSV_PATTERN

public static final java.lang.String CSV_PATTERN
The rather involved pattern used to match CSV's consists of three alternations: the first matches a quoted field, the second unquoted, the third a null field.

See Also:
Constant Field Values
Constructor Detail

CSVRE

public CSVRE()
Construct a regex-based CSV parser.

Method Detail

main

public static void main(java.lang.String[] argv)
                 throws java.io.IOException
Throws:
java.io.IOException

process

public void process(java.io.BufferedReader in)
             throws java.io.IOException
Process one file. Delegates to parse() a line at a time

Throws:
java.io.IOException

parse

public java.util.List<java.lang.String> parse(java.lang.String line)
Parse one line.

Returns:
List of Strings, minus their double quotes


Copyright © 1996-2004 Ian F. Darwin. See license.html for usage license.