in src/main/java/org/apache/commons/csv/CSVFormat.java [2315:2353]
private void printWithEscapes(final CharSequence charSeq, final Appendable appendable) throws IOException {
int start = 0;
int pos = 0;
final int end = charSeq.length();
final char[] delimArray = getDelimiterCharArray();
final int delimLength = delimArray.length;
final char escape = getEscapeChar();
while (pos < end) {
char c = charSeq.charAt(pos);
final boolean isDelimiterStart = isDelimiter(c, charSeq, pos, delimArray, delimLength);
final boolean isCr = c == Constants.CR;
final boolean isLf = c == Constants.LF;
if (isCr || isLf || c == escape || isDelimiterStart) {
// write out segment up until this char
if (pos > start) {
appendable.append(charSeq, start, pos);
}
if (isLf) {
c = 'n';
} else if (isCr) {
c = 'r';
}
escape(c, appendable);
if (isDelimiterStart) {
for (int i = 1; i < delimLength; i++) {
pos++;
escape(charSeq.charAt(pos), appendable);
}
}
start = pos + 1; // start on the current char after this one
}
pos++;
}
// write last segment
if (pos > start) {
appendable.append(charSeq, start, pos);
}
}