@@ -348,16 +348,7 @@ private Token parseEncapsulatedToken(final Token token) throws IOException {
348348 }
349349 }
350350 } else if (isEscape (c )) {
351- if (isEscapeDelimiter ()) {
352- token .content .append (delimiter );
353- } else {
354- final int unescaped = readEscape ();
355- if (unescaped == EOF ) { // unexpected char after escape
356- token .content .append ((char ) c ).append ((char ) reader .getLastChar ());
357- } else {
358- token .content .append ((char ) unescaped );
359- }
360- }
351+ appendNextEscapedCharacterToToken (token );
361352 } else if (isEndOfFile (c )) {
362353 if (lenientEof ) {
363354 token .type = Token .Type .EOF ;
@@ -412,16 +403,7 @@ private Token parseSimpleToken(final Token token, int ch) throws IOException {
412403 }
413404 // continue
414405 if (isEscape (ch )) {
415- if (isEscapeDelimiter ()) {
416- token .content .append (delimiter );
417- } else {
418- final int unescaped = readEscape ();
419- if (unescaped == EOF ) { // unexpected char after escape
420- token .content .append ((char ) ch ).append ((char ) reader .getLastChar ());
421- } else {
422- token .content .append ((char ) unescaped );
423- }
424- }
406+ appendNextEscapedCharacterToToken (token );
425407 } else {
426408 token .content .append ((char ) ch );
427409 }
@@ -435,6 +417,27 @@ private Token parseSimpleToken(final Token token, int ch) throws IOException {
435417 return token ;
436418 }
437419
420+ /**
421+ * Appends the next escaped character to the token's content.
422+ *
423+ * @param token
424+ * the current token
425+ * @throws IOException
426+ * on stream access error
427+ */
428+ private void appendNextEscapedCharacterToToken (final Token token ) throws IOException {
429+ if (isEscapeDelimiter ()) {
430+ token .content .append (delimiter );
431+ } else {
432+ final int unescaped = readEscape ();
433+ if (unescaped == EOF ) { // unexpected char after escape
434+ token .content .append (escape ).append ((char ) reader .getLastChar ());
435+ } else {
436+ token .content .append ((char ) unescaped );
437+ }
438+ }
439+ }
440+
438441 /**
439442 * Greedily accepts \n, \r and \r\n This checker consumes silently the second control-character...
440443 *
0 commit comments