Skip to content

Commit 1d7ebab

Browse files
committed
use strategy encapsulator in printer rather than assuming double-quote
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/csv/trunk@558885 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1418238 commit 1d7ebab

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/java/org/apache/commons/csv/CSVPrinter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public void print(String value) {
250250
* @param value needs to be escaped and quoted
251251
* @return the value, escaped and quoted
252252
*/
253-
private static String escapeAndQuote(String value) {
253+
private String escapeAndQuote(String value) {
254254
// the initial count is for the preceding and trailing quotes
255255
int count = 2;
256256
for (int i = 0; i < value.length(); i++) {
@@ -266,13 +266,15 @@ private static String escapeAndQuote(String value) {
266266
}
267267
}
268268
StringBuffer sb = new StringBuffer(value.length() + count);
269-
sb.append('"');
269+
sb.append(strategy.getEncapsulator());
270270
for (int i = 0; i < value.length(); i++) {
271271
char c = value.charAt(i);
272+
273+
if (c == strategy.getEncapsulator()) {
274+
sb.append('\\').append(c);
275+
continue;
276+
}
272277
switch (c) {
273-
case '\"' :
274-
sb.append("\\\"");
275-
break;
276278
case '\n' :
277279
sb.append("\\n");
278280
break;
@@ -286,7 +288,7 @@ private static String escapeAndQuote(String value) {
286288
sb.append(c);
287289
}
288290
}
289-
sb.append('"');
291+
sb.append(strategy.getEncapsulator());
290292
return sb.toString();
291293
}
292294

0 commit comments

Comments
 (0)