Package org.cthing.escapers
Class CsvEscaper
java.lang.Object
org.cthing.escapers.CsvEscaper
Escapes string and character arrays according to
RFC-4180. If a string contains a comma,
carriage return, line feed, or a double quote, the string must be surrounded by double quotes and
any double quotes within the string must be replaced with two consecutive double quotes
(i.e. a single " becomes "").
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringescape(char[] charArr) Applies CSV escaping to the specified character array.static Stringescape(char[] charArr, int offset, int length) Applies CSV escaping to the specified character array.static voidApplies CSV escaping to the specified character array and writes the result to the specified writer.static voidApplies CSV escaping to the specified character array and writes the result to the specified writer.static Stringescape(CharSequence charSequence) Applies CSV escaping to the specified string.static voidescape(CharSequence charSequence, Writer writer) Applies CSV escaping to the specified string and writes the result to the specified writer.
-
Method Details
-
escape
Applies CSV escaping to the specified string.- Parameters:
charSequence- String to escape- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
@WillNotClose public static void escape(CharSequence charSequence, Writer writer) throws IOException Applies CSV escaping to the specified string and writes the result to the specified writer.- Parameters:
charSequence- String to escapewriter- Writer to which the escaped string is written- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
Applies CSV escaping to the specified character array.- Parameters:
charArr- Character array to escape- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies CSV escaping to the specified character array.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in array- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies CSV escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapewriter- Writer to which the escaped string is written- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, int offset, int length, Writer writer) throws IOException Applies CSV escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arraywriter- Writer to which the escaped string is written- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-