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
This commit is contained in:
parent
14182380d5
commit
1d7ebab211
|
@ -250,7 +250,7 @@ public class CSVPrinter {
|
|||
* @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 @@ public class CSVPrinter {
|
|||
}
|
||||
}
|
||||
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 @@ public class CSVPrinter {
|
|||
sb.append(c);
|
||||
}
|
||||
}
|
||||
sb.append('"');
|
||||
sb.append(strategy.getEncapsulator());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue