Skip to content

Commit 0e8ddb3

Browse files
committed
Move escapeLiteral to PatternSequence
1 parent a44e3c9 commit 0e8ddb3

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatter.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,31 @@ boolean isConstantForDurationOf(final ChronoUnit thresholdPrecision) {
422422
return precision.compareTo(thresholdPrecision) >= 0;
423423
}
424424

425+
static String escapeLiteral(String literal) {
426+
StringBuilder sb = new StringBuilder(literal.length() + 2);
427+
boolean inSingleQuotes = false;
428+
for (int i = 0; i < literal.length(); i++) {
429+
char c = literal.charAt(i);
430+
if (c == '\'') {
431+
if (inSingleQuotes) {
432+
sb.append("'");
433+
}
434+
inSingleQuotes = false;
435+
sb.append("''");
436+
} else {
437+
if (!inSingleQuotes) {
438+
sb.append("'");
439+
}
440+
inSingleQuotes = true;
441+
sb.append(c);
442+
}
443+
}
444+
if (inSingleQuotes) {
445+
sb.append("'");
446+
}
447+
return sb.toString();
448+
}
449+
425450
@Override
426451
public boolean equals(final Object object) {
427452
if (this == object) {
@@ -479,31 +504,6 @@ PatternSequence tryMerge(PatternSequence other, ChronoUnit thresholdPrecision) {
479504
}
480505
return null;
481506
}
482-
483-
static String escapeLiteral(String literal) {
484-
StringBuilder sb = new StringBuilder(literal.length() + 2);
485-
boolean inSingleQuotes = false;
486-
for (int i = 0; i < literal.length(); i++) {
487-
char c = literal.charAt(i);
488-
if (c == '\'') {
489-
if (inSingleQuotes) {
490-
sb.append("'");
491-
}
492-
inSingleQuotes = false;
493-
sb.append("''");
494-
} else {
495-
if (!inSingleQuotes) {
496-
sb.append("'");
497-
}
498-
inSingleQuotes = true;
499-
sb.append(c);
500-
}
501-
}
502-
if (inSingleQuotes) {
503-
sb.append("'");
504-
}
505-
return sb.toString();
506-
}
507507
}
508508

509509
/**

0 commit comments

Comments
 (0)