From: <zep...@us...> - 2008-08-31 12:33:53
|
Revision: 399 http://flatpack.svn.sourceforge.net/flatpack/?rev=399&view=rev Author: zepernick Date: 2008-08-31 12:34:01 +0000 (Sun, 31 Aug 2008) Log Message: ----------- stopped the fixed width parser from removing leading spaces in the data element. Added the rTrim() method in the ParserUtils Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/util/FixedWidthParserUtils.java trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/util/FixedWidthParserUtils.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/util/FixedWidthParserUtils.java 2008-03-18 12:31:17 UTC (rev 398) +++ trunk/flatpack/src/main/java/net/sf/flatpack/util/FixedWidthParserUtils.java 2008-08-31 12:34:01 UTC (rev 399) @@ -67,7 +67,9 @@ final ColumnMetaData colMetaDataObj = (ColumnMetaData) columnMetaData.get(i); final String tempValue = lineToParse.substring(recPosition - 1, recPosition + colMetaDataObj.getColLength() - 1); recPosition += colMetaDataObj.getColLength(); - splitResult.add(tempValue.trim()); + //make sure that we preserve leading spaces as they most likely are there intentionally. + //This was previously issuing a trim() + splitResult.add(ParserUtils.rTrim(tempValue)); } return splitResult; @@ -85,7 +87,7 @@ */ public static String getCMDKey(final Map columnMD, final String line) { if (columnMD.size() == 1) { - // no <RECORD> elments were specifed for this parse, just return the + // no <RECORD> elements were specified for this parse, just return the // detail id return FPConstants.DETAIL_ID; } @@ -131,7 +133,7 @@ */ public static String getCMDKey(final MetaData columnMD, final String line) { if (!columnMD.isAnyRecordFormatSpecified()) { - // no <RECORD> elments were specifed for this parse, just return the + // no <RECORD> elements were specified for this parse, just return the // detail id return FPConstants.DETAIL_ID; } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2008-03-18 12:31:17 UTC (rev 398) +++ trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2008-08-31 12:34:01 UTC (rev 399) @@ -243,7 +243,7 @@ } /** - * Removes empty space from the begining of a string + * Removes empty space from the beginning of a string * * @param value - * to be trimmed @@ -267,9 +267,10 @@ return trimmed; } + /** - * Removes empty space from the begining of a string, except for tabs + * Removes empty space from the beginning of a string, except for tabs * * @param value - * to be trimmed @@ -293,7 +294,32 @@ return trimmed; } + + /** + * Removes empty space from the end of a string + * + * @param value - + * to be trimmed + * @return String + */ + public static String rTrim(final String value) { + if (value == null) { + return null; + } + String trimmed = value; + int offset = value.length() - 1; + while (offset > -1 && (value.charAt(offset) == ' ' || value.charAt(offset) == '\t')) { + offset--; + } + + if (offset < value.length() - 1) { + trimmed = value.substring(0,offset + 1); + } + + return trimmed; + } + /** * Will return a null if the String is empty returns the * trimmed string otherwise. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |