org.unbescape.csv
Class CsvEscape

Object
  extended by org.unbescape.csv.CsvEscape

public final class CsvEscape
extends Object

Utility class for performing CSV escape/unescape operations.

Features

Specific features of the CSV escape/unescape operations performed by means of this class:

Input/Output

There are two different input/output modes that can be used in escape/unescape operations:

Specific instructions for Microsoft Excel-compatible files

In order for Microsoft Excel to correcly open a CSV file —including field values with line breaks— these rules should be followed:

(Note unbescape will perform escaping of field values only, so it will take care of enclosing in double-quotes, using unix-style line breaks inside values, etc. But separating fields (e.g. with ;), delimiting records (e.g. with \r\n) and using the correct character encoding when writing CSV files will be the responsibility of the application calling unbescape.)

The described format for Excel is also supported by OpenOffice.org Calc (File -> Open...) and also Google Spreadsheets (File -> Import...)

References

The following references apply:

Since:
1.0
Author:
Daniel Fernández

Method Summary
static void escapeCsv(char[] text, int offset, int len, Writer writer)
           Perform a CSV escape operation on a char[] input.
static String escapeCsv(String text)
           Perform a CSV escape operation on a String input.
static void unescapeCsv(char[] text, int offset, int len, Writer writer)
           Perform a CSV unescape operation on a char[] input.
static String unescapeCsv(String text)
           Perform a CSV unescape operation on a String input.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

escapeCsv

public static String escapeCsv(String text)

Perform a CSV escape operation on a String input.

This method is thread-safe.

Parameters:
text - the String to be escaped.
Returns:
The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if text is null.

escapeCsv

public static void escapeCsv(char[] text,
                             int offset,
                             int len,
                             Writer writer)
                      throws IOException

Perform a CSV escape operation on a char[] input.

This method is thread-safe.

Parameters:
text - the char[] to be escaped.
offset - the position in text at which the escape operation should start.
len - the number of characters in text that should be escaped.
writer - the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if text is null.
Throws:
IOException

unescapeCsv

public static String unescapeCsv(String text)

Perform a CSV unescape operation on a String input.

This method is thread-safe.

Parameters:
text - the String to be unescaped.
Returns:
The unescaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no unescaping modifications were required (and no additional String objects will be created during processing). Will return null if text is null.

unescapeCsv

public static void unescapeCsv(char[] text,
                               int offset,
                               int len,
                               Writer writer)
                        throws IOException

Perform a CSV unescape operation on a char[] input.

This method is thread-safe.

Parameters:
text - the char[] to be unescaped.
offset - the position in text at which the unescape operation should start.
len - the number of characters in text that should be unescaped.
writer - the java.io.Writer to which the unescaped result will be written. Nothing will be written at all to this writer if text is null.
Throws:
IOException


Copyright © 2014 The UNBESCAPE team. All rights reserved.