/** * Encodes the string, so that the string can safely be used in CSV files. If the string does not need quoting, the * original string is returned unchanged. * * @param original the unquoted string. * @return The quoted string */ public String doQuoting( final String original ) { if ( forceQuote || isQuotingNeeded( original ) ) { final StringBuffer retval = new StringBuffer( original.length() + 5 ); // a safe guess most of the time. retval.append( quate ); applyQuote( retval, original ); retval.append( quate ); return retval.toString(); } else { return original; } }
/** * A streaming version of the quoting algorithm for more performance. Encodes the string, so that the string can * safely be used in CSV files. If the string does not need quoting, the original string is returned unchanged. * * @param original the unquoted string. * @param writer the writer. * @throws IOException if an IO error occured. */ public void doQuoting( final String original, final Writer writer ) throws IOException { if ( isQuotingNeeded( original ) ) { writer.write( quate ); applyQuote( writer, original ); writer.write( quate ); } else { writer.write( original ); } }
/** * Decodes the string, so that all escape sequences get removed. If the string was not quoted, then the string is * returned unchanged. * * @param nativeString the quoted string. * @return The unquoted string. */ public String undoQuoting( final String nativeString ) { if ( isQuotingNeeded( nativeString ) ) { final StringBuilder b = new StringBuilder( nativeString.length() ); final int length = nativeString.length() - 1; int start = 1; int pos = start; while ( pos != -1 ) { pos = nativeString.indexOf( doubleQuate, start ); if ( pos == -1 ) { b.append( nativeString.substring( start, length ) ); } else { b.append( nativeString.substring( start, pos ) ); start = pos + 1; } } return b.toString(); } else { return nativeString; } }
/** * A streaming version of the quoting algorithm for more performance. Encodes the string, so that the string can * safely be used in CSV files. If the string does not need quoting, the original string is returned unchanged. * * @param original the unquoted string. * @param writer the writer. * @throws IOException if an IO error occured. */ public void doQuoting (final String original, final Writer writer) throws IOException { if (isQuotingNeeded(original)) { writer.write(quate); applyQuote(writer, original); writer.write(quate); } else { writer.write(original); } }
/** * Encodes the string, so that the string can safely be used in CSV files. If the string * does not need quoting, the original string is returned unchanged. * * @param original the unquoted string. * @return The quoted string */ public String doQuoting (final String original) { if (isQuotingNeeded(original)) { final StringBuffer retval = new StringBuffer(original.length() + 5); // a safe guess most of the time. retval.append(quate); applyQuote(retval, original); retval.append(quate); return retval.toString(); } else { return original; } }
if (isQuotingNeeded(nativeString))