@@ -2236,35 +2236,32 @@ public synchronized void printRecord(final Appendable appendable, final Object..
22362236 * Note: Must only be called if escaping is enabled, otherwise can throw exceptions.
22372237 */
22382238 private void printWithEscapes (final CharSequence charSeq , final Appendable appendable ) throws IOException {
2239-
2240- final char [] delimArray = getDelimiterCharArray ();
2241- final int delimLength = delimArray .length ;
2242- final char escape = getEscapeChar ();
2243-
22442239 int start = 0 ;
22452240 int pos = 0 ;
22462241 final int end = charSeq .length ();
2242+ final char [] delimArray = getDelimiterCharArray ();
2243+ final int delimLength = delimArray .length ;
2244+ final char escape = getEscapeChar ();
22472245
22482246 while (pos < end ) {
22492247 char c = charSeq .charAt (pos );
2250-
2248+ final boolean isDelimiterStart = isDelimiter ( c , charSeq , pos , delimArray , delimLength );
22512249 final boolean isCr = c == Constants .CR ;
22522250 final boolean isLf = c == Constants .LF ;
2253- if (isDelimiter ( c , charSeq , pos , delimArray , delimLength ) || isCr || isLf || c == escape ) {
2254- // handle escaped character or delimiter
2251+ if (isCr || isLf || c == escape || isDelimiterStart ) {
2252+ // write out segment up until this char
22552253 if (pos > start ) {
22562254 appendable .append (charSeq , start , pos );
2257- // write out segment until this char
22582255 }
22592256 if (isLf ) {
2260- c = 'n' ; // convert isLF to 'n'
2257+ c = 'n' ;
22612258 } else if (isCr ) {
2262- c = 'r' ; // convert isCR to 'r'
2259+ c = 'r' ;
22632260 }
22642261 escape (c , appendable );
2265- {
2266- while (++ pos < end && isDelimiter ( charSeq . charAt ( pos ), delim , delimLength ) ) {
2267-
2262+ if ( isDelimiterStart ) {
2263+ for ( int i = 1 ; i < delimLength ; i ++ ) {
2264+ pos ++;
22682265 escape (charSeq .charAt (pos ), appendable );
22692266 }
22702267 }
0 commit comments