From: <zep...@us...> - 2006-10-31 20:00:21
|
Revision: 162 http://svn.sourceforge.net/pzfilereader/?rev=162&view=rev Author: zepernick Date: 2006-10-31 12:00:17 -0800 (Tue, 31 Oct 2006) Log Message: ----------- - handle null's for lTrim(), lTrimKeepTabs, and splitLine() - splitLine now returns nulls for elements which are empty and have not been qualified - Added a trimToNull method. - All current tests pass with these changes Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-31 17:33:49 UTC (rev 161) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-31 20:00:17 UTC (rev 162) @@ -73,6 +73,14 @@ */ public static List splitLine(String line, final char delimiter, final char qualifier) { final ArrayList list = new ArrayList(); + + if (line == null) { + return list; + } else if (line.trim().length() == 0){ + list.add(null); + return list; + } + boolean beginQualifier = false; // this will be used for delimted files that have some items qualified // and some items dont @@ -99,7 +107,8 @@ // make sure that this is not just an empty column with no // qualifiers. ie "data",,"data" if (currentChar == delimiter) { - list.add(sb.toString()); + //list.add(sb.toString()); + list.add(null); sb.delete(0, sb.length()); beginNoQualifier = false; continue;// grab the next char @@ -175,7 +184,8 @@ // check to see if we need to add the last column in..this will // happen on empty columns // add the last column - list.add(beginNoQualifier ? lTrim(sb.toString().trim()) : sb.toString()); + list.add(!beginQualifier ? lTrim(trimToNull(sb.toString())) : sb.toString()); + //list.add(null); } sb = null; @@ -210,6 +220,10 @@ * @return String */ public static String lTrim(final String value) { + if (value == null) { + return null; + } + String trimmed = value; int offset = 0; final int maxLength = value.length(); @@ -232,6 +246,10 @@ * @return String */ public static String lTrimKeepTabs(final String value) { + if (value == null) { + return null; + } + String trimmed = value; int offset = 0; final int maxLength = value.length(); @@ -245,6 +263,25 @@ return trimmed; } + + /** + * Will return a null if the String is empty returns the + * trimmed string otherwise. + * + * @param value + * to be trimmed + * @return String + */ + public static String trimToNull(final String value) { + if (value == null) { + return null; + } + + final String ret = value.trim(); + + return ret.length() == 0 ? null : ret; + + } /** * Removes a single string character from a given string This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |