Skip to content

Commit

Permalink
Rename "Conversion Modifier" to "Option"
Browse files Browse the repository at this point in the history
"Option" text aligns with the logback manual. Plus, it's nice and
simple (easy to type).
  • Loading branch information
tony19 committed Jun 10, 2013
1 parent 60168e8 commit 6de473f
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 115 deletions.
132 changes: 66 additions & 66 deletions src/main/java/ch/qos/logback/core/pattern/parser2/PatternInfo.java
Expand Up @@ -18,206 +18,206 @@

/**
* Contains the individual parts of a single layout pattern, including
* format modifier, conversion modifier, and name.
*
* format modifier, conversion option, and name.
*
* The individual parts are defined as (without the square brackets):
*
*
* <blockquote>
* <pre>%[format][name]{[conversion]}</pre>
* <pre>%[format][name]{[option]}</pre>
* </blockquote>
*
*
* The "name" field must be one of {@link PatternNames}.
*/
public class PatternInfo {
private String formatModifier;
private String conversionModifier;
private String option;
private String name;
private String contents;
private String original;
private int start;
private int end;
private List<PatternInfo> children;

/**
* Gets the format modifier
*
*
* @return the format modifier
*/
public String getFormatModifier() { return formatModifier; }

/**
* Sets the format modifier
*
*
* @param s the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setFormatModifier(String s) {
formatModifier = s;
return this;
public PatternInfo setFormatModifier(String s) {
formatModifier = s;
return this;
}

/**
* Gets the conversion modifier
*
* @return the conversion modifier
* Gets the conversion option
*
* @return the conversion option
*/
public String getConversionModifier() { return conversionModifier; }
public String getOption() { return option; }

/**
* Sets the conversion modifier
*
* Sets the conversion option
*
* @param s the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setConversionModifier(String s) {
conversionModifier = s;
public PatternInfo setOption(String s) {
option = s;
return this;
}

/**
* Gets the name of this layout pattern
*
*
* @return the name
*/
public String getName() { return name; }

/**
* Sets the name of this layout pattern
*
*
* @param s the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setName(String s) {
public PatternInfo setName(String s) {
name = s;
return this;
}

/**
* Gets the starting position of this sub-pattern within
* Gets the starting position of this sub-pattern within
* the full layout pattern
*
*
* @return the starting zero-based index
*/
public int start() { return start; }

/**
* Sets the starting position of this sub-pattern within
* the full layout pattern
*
*
* @param index the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setStart(int index) {
start = index;
public PatternInfo setStart(int index) {
start = index;
return this;
}

/**
* Gets the end position of this sub-pattern within the
* Gets the end position of this sub-pattern within the
* full layout pattern
*
*
* @return the end zero-based index
*/
public int end() { return end; }

/**
* Sets the end position of this sub-pattern within the
* full layout pattern
*
*
* @param index the desired value
*/
public PatternInfo setEnd(int index) {
public PatternInfo setEnd(int index) {
end = index;
return this;
}

/**
* Gets the contents (inner text of a grouping)
*
*
* @return the contents
*/
public String contents() { return contents; }

/**
* Sets the contents (inner text of a grouping)
*
*
* @param s the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setGroup(String s) {
public PatternInfo setGroup(String s) {
contents = s;
return this;
}

/**
* Gets the children (sub-patterns from inner text of a grouping)
* of this sub-pattern
*
* @return the children
*
* @return the children
*/
public List<PatternInfo> getChildren() { return children; }

/**
* Sets the children (sub-patterns from inner text of a grouping)
* of this sub-pattern
*
*
* @param children the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setChildren(List<PatternInfo> children) {
this.children = children;
return this;
}

/**
* Gets the original sub-pattern text
*
*
* @return the complete sub-pattern
*/
public String getOriginal() { return original; }

/**
* Sets the original sub-pattern text
*
*
* @param s the desired value
* @return this {@code LayoutPatternInfo}
*/
public PatternInfo setOriginal(String s) {
original = s;
return this;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
appendString(sb, 0);
return sb.toString();
}

/**
* Appends a specified number of tabs to a string builder
*
*
* @param sb destination string builder
* @param count number of tabs to append
*/
private void appendTabs(StringBuilder sb, int count) {
for (int i = 0; i < count; i++) sb.append(" ");
}

/**
* Appends a formatted string representation of
* this {@code LayoutPatternInfo}
*
*
* @param sb destination string builder
* @param level tab level
*/
private void appendString(StringBuilder sb, int level) {

appendTabs(sb, level);
sb.append("{\n");
appendTabs(sb, level+1);
sb.append("Indexes: [").append(start).append(",").append(end).append("),\n");

if (original != null) {
appendTabs(sb, level+1);
sb.append("Original: ").append(original).append(",\n");
Expand All @@ -234,18 +234,18 @@ private void appendString(StringBuilder sb, int level) {
appendTabs(sb, level+1);
sb.append("Format Mod: ").append(formatModifier).append(",\n");
}
if (conversionModifier != null) {
if (option != null) {
appendTabs(sb, level+1);
sb.append("Conv Mod: ").append(conversionModifier).append(",\n");
sb.append("Option: ").append(option).append(",\n");
}
if (children != null && !children.isEmpty()) {
appendTabs(sb, level+1);
sb.append("Children: {\n");

for (PatternInfo c : children) {
c.appendString(sb, level+2);
}

appendTabs(sb, level+1);
sb.append("}\n");
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class PatternParser {
// group names
private static final String FORMAT = "fmt";
private static final String NAME = "name";
private static final String CONVRSN = "cnv";
private static final String OPTION = "opt";
private static final String GROUP = "grp";

// general regex pattern for layout patterns
Expand Down Expand Up @@ -82,8 +82,8 @@ public int compare(String s1, String s2) {
"%" + // pattern starter (required)
"(?<" + FORMAT + ">[-.]{0,2}\\d+(?:\\.\\d+)?)?" + // format modifier (optional)
"(?<" + NAME + ">" + names + ")?" + // pattern name (optional)
"(?:\\((?<" + GROUP + ">.*)\\))?" + // grouping (optional)
"(?:\\{(?<" + CONVRSN + ">.*)\\})?"; // conversion modifier (optional)
"(?:\\((?<" + GROUP + ">[^)]*?)\\))?" + // grouping (optional)
"(?:\\{(?<" + OPTION + ">[^}]*?)\\})?"; // conversion option (optional)

REGEX_PATTERN = NamedPattern.compile(REGEX);
}
Expand Down Expand Up @@ -118,16 +118,16 @@ public static List<PatternInfo> parse(String layoutPattern) {
// the layout pattern (this is not to be confused with a
// regex capture group)
String group = getTextUpToFirstCloser(m.group(GROUP), '(', ')', false);
String conv = getTextUpToFirstCloser(m.group(CONVRSN), '{', '}', true);
String opt = getTextUpToFirstCloser(buf + m.group(OPTION), '{', '}', true);

PatternInfo inf = new PatternInfo();

inf.setOriginal(m.group(0))
.setStart(start)
.setEnd(m.end())
.setGroup(group)
.setName(m.group(NAME))
.setConversionModifier(conv)
.setOption(opt)
.setFormatModifier(m.group(FORMAT));

// recursively set children
Expand Down Expand Up @@ -178,7 +178,6 @@ private static String getTextUpToFirstCloser(String s, char opener, char closer,
int numOpeners = countOccurences(s, opener);
int numClosers = countOccurences(s, closer);
if (numOpeners != numClosers) {

// find first non-escaped closer
int i = -1;
while ((i = s.indexOf(closer, i+1)) >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/qos/logback/decoder/DateParser.java
Expand Up @@ -37,7 +37,7 @@ public void captureField(LoggingEvent event, String fieldAsStr, PatternInfo info
// default to ISO8601 is no conversion pattern given
String convPattern = CoreConstants.ISO8601_PATTERN;
if (info != null) {
convPattern = info.getConversionModifier();
convPattern = info.getOption();
if (convPattern == null || convPattern.isEmpty() || convPattern.equals(CoreConstants.ISO8601_STR)) {
convPattern = CoreConstants.ISO8601_PATTERN;
}
Expand Down

0 comments on commit 6de473f

Please sign in to comment.