mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
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:
parent
e97b55f884
commit
c465263306
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue