in src/main/java/org/apache/log4j/pattern/NameAbbreviator.java [46:129]
public static NameAbbreviator getAbbreviator(final String pattern) {
if (pattern.length() > 0) {
// if pattern is just spaces and numbers then
// use MaxElementAbbreviator
String trimmed = pattern.trim();
if (trimmed.length() == 0) {
return DEFAULT;
}
int i = 0;
if (trimmed.length() > 0) {
if (trimmed.charAt(0) == '-') {
i++;
}
for (;
(i < trimmed.length()) &&
(trimmed.charAt(i) >= '0') &&
(trimmed.charAt(i) <= '9');
i++) {
}
}
//
// if all blanks and digits
//
if (i == trimmed.length()) {
int elements = Integer.parseInt(trimmed);
if (elements >= 0) {
return new MaxElementAbbreviator(elements);
} else {
return new DropElementAbbreviator(-elements);
}
}
ArrayList fragments = new ArrayList(5);
char ellipsis;
int charCount;
int pos = 0;
while ((pos < trimmed.length()) && (pos >= 0)) {
int ellipsisPos = pos;
if (trimmed.charAt(pos) == '*') {
charCount = Integer.MAX_VALUE;
ellipsisPos++;
} else {
if ((trimmed.charAt(pos) >= '0') && (trimmed.charAt(pos) <= '9')) {
charCount = trimmed.charAt(pos) - '0';
ellipsisPos++;
} else {
charCount = 0;
}
}
ellipsis = '\0';
if (ellipsisPos < trimmed.length()) {
ellipsis = trimmed.charAt(ellipsisPos);
if (ellipsis == '.') {
ellipsis = '\0';
}
}
fragments.add(new PatternAbbreviatorFragment(charCount, ellipsis));
pos = trimmed.indexOf(".", pos);
if (pos == -1) {
break;
}
pos++;
}
return new PatternAbbreviator(fragments);
}
//
// no matching abbreviation, return defaultAbbreviator
//
return DEFAULT;
}