commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r558885 - /jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVPrinter.java
Date Mon, 23 Jul 2007 22:32:44 GMT
Author: mbenson
Date: Mon Jul 23 15:32:42 2007
New Revision: 558885

URL: http://svn.apache.org/viewvc?view=rev&rev=558885
Log:
use strategy encapsulator in printer rather than assuming double-quote

Modified:
    jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVPrinter.java

Modified: jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVPrinter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVPrinter.java?view=diff&rev=558885&r1=558884&r2=558885
==============================================================================
--- jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVPrinter.java (original)
+++ jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVPrinter.java Mon
Jul 23 15:32:42 2007
@@ -250,7 +250,7 @@
    * @param value needs to be escaped and quoted
    * @return the value, escaped and quoted
    */
-  private static String escapeAndQuote(String value) {
+  private String escapeAndQuote(String value) {
     // the initial count is for the preceding and trailing quotes
     int count = 2;
     for (int i = 0; i < value.length(); i++) {
@@ -266,13 +266,15 @@
       }
     }
     StringBuffer sb = new StringBuffer(value.length() + count);
-    sb.append('"');
+    sb.append(strategy.getEncapsulator());
     for (int i = 0; i < value.length(); i++) {
       char c = value.charAt(i);
+
+      if (c == strategy.getEncapsulator()) {
+        sb.append('\\').append(c);
+        continue;
+      }
       switch (c) {
-        case '\"' :
-          sb.append("\\\"");
-          break;
         case '\n' :
           sb.append("\\n");
           break;
@@ -286,7 +288,7 @@
           sb.append(c);
       }
     }
-    sb.append('"');
+    sb.append(strategy.getEncapsulator());
     return sb.toString();
   }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message