A few refactorings in anticipation of more formats that needs some common functionality

git-svn-id: https://zxing.googlecode.com/svn/trunk@315 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-03-26 14:46:57 +00:00
parent e97b55f884
commit c465263306
2 changed files with 24 additions and 24 deletions

View file

@ -67,7 +67,7 @@ abstract class AbstractDoCoMoParsedResult extends ParsedReaderResult {
if (matches == null) {
matches = new Vector(3); // lazy init
}
matches.addElement(unescape(rawText.substring(start, i)));
matches.addElement(unescapeBackslash(rawText.substring(start, i)));
i++;
done = true;
}
@ -93,29 +93,6 @@ abstract class AbstractDoCoMoParsedResult extends ParsedReaderResult {
return matches == null ? null : matches[0];
}
private static String unescape(String escaped) {
if (escaped != null) {
int backslash = escaped.indexOf((int) '\\');
if (backslash >= 0) {
int max = escaped.length();
StringBuffer unescaped = new StringBuffer(max - 1);
unescaped.append(escaped.toCharArray(), 0, backslash);
boolean nextIsEscaped = false;
for (int i = backslash; i < max; i++) {
char c = escaped.charAt(i);
if (nextIsEscaped || c != '\\') {
unescaped.append(c);
nextIsEscaped = false;
} else {
nextIsEscaped = true;
}
}
return unescaped.toString();
}
}
return escaped;
}
static void maybeAppend(String value, StringBuffer result) {
if (value != null) {
result.append('\n');

View file

@ -76,4 +76,27 @@ public abstract class ParsedReaderResult {
return getDisplayResult();
}
static String unescapeBackslash(String escaped) {
if (escaped != null) {
int backslash = escaped.indexOf((int) '\\');
if (backslash >= 0) {
int max = escaped.length();
StringBuffer unescaped = new StringBuffer(max - 1);
unescaped.append(escaped.toCharArray(), 0, backslash);
boolean nextIsEscaped = false;
for (int i = backslash; i < max; i++) {
char c = escaped.charAt(i);
if (nextIsEscaped || c != '\\') {
unescaped.append(c);
nextIsEscaped = false;
} else {
nextIsEscaped = true;
}
}
return unescaped.toString();
}
}
return escaped;
}
}