1 package ch.qos.logback.core.pattern.util;
2
3 import ch.qos.logback.core.CoreConstants;
4 import ch.qos.logback.core.rolling.helper.FileNamePattern;
5
6 /**
7 * This implementation is intended for use in {@link FileNamePattern}.
8 *
9 * @author Ceki Gülcü
10 */
11 public class AlmostAsIsEscapeUtil implements IEscapeUtil {
12
13 /**
14 * Do not perform any character escaping, except for '%'.
15 *
16 * <p>
17 * Here is the rationale. First, filename patterns do not include escape
18 * combinations such as \r or \n. Moreover, characters which have special
19 * meaning in logback parsers, such as '(', ')', '{', or '}' cannot be part of
20 * file names (so me thinks). Thus, the only character that needs escaping is
21 * '%'.
22 *
23 * <p>
24 * Note that this method assumes that it is called after the escape character
25 * has been consumed.
26 */
27 public void escape(String escapeChars, StringBuffer buf, char next,
28 int pointer) {
29
30 if (next == CoreConstants.PERCENT_CHAR) {
31 buf.append(CoreConstants.PERCENT_CHAR);
32 } else {
33 // restitute the escape char (because it was consumed
34 // before this method was called).
35 buf.append("\\");
36 // restitute the next character
37 buf.append(next);
38 }
39 }
40 }