import java.util.Vector;
/**
- * See
+ * <p>See
* <a href="http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/about/s2.html">
- * DoCoMo's documentation</a> about the result types represented by subclasses of this class.
+ * DoCoMo's documentation</a> about the result types represented by subclasses of this class.</p>
+ *
+ * <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
+ * on exception-based mechanisms during parsing.</p>
*
* @author srowen@google.com (Sean Owen)
*/
// to run in a J2ME enviroment, where this unavailable.
static String[] matchPrefixedField(String prefix, String rawText) {
+ return matchPrefixedField(prefix, rawText, ';');
+ }
+
+ static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
Vector matches = null;
int i = 0;
int max = rawText.length();
int start = i; // Found the start of a match here
boolean done = false;
while (!done) {
- i = rawText.indexOf((int) ';', i);
+ i = rawText.indexOf((int) endChar, i);
if (i < 0) {
- // No terminating semicolon? uh, done. Set i such that loop terminates and break
+ // No terminating end character? uh, done. Set i such that loop terminates and break
i = rawText.length();
done = true;
- } else if (rawText.charAt(i-1) == '\\') {
+ } else if (rawText.charAt(i - 1) == '\\') {
// semicolon was escaped so continue
i++;
} else {
}
}
}
- if (matches == null) {
+ if (matches == null || matches.isEmpty()) {
return null;
}
int size = matches.size();
}
static String matchSinglePrefixedField(String prefix, String rawText) {
- String[] matches = matchPrefixedField(prefix, rawText);
- return matches == null ? null : matches[0];
+ return matchSinglePrefixedField(prefix, rawText, ';');
}
- static String[] matchRequiredPrefixedField(String prefix, String rawText) {
- String[] result = matchPrefixedField(prefix, rawText);
- if (result == null) {
- throw new IllegalArgumentException("Did not match prefix " + prefix);
- }
- return result;
+ static String matchSinglePrefixedField(String prefix, String rawText, char endChar) {
+ String[] matches = matchPrefixedField(prefix, rawText, endChar);
+ return matches == null ? null : matches[0];
}
private static String unescape(String escaped) {
}
}
+ static void maybeAppend(String[] value, StringBuffer result) {
+ if (value != null) {
+ for (int i = 0; i < value.length; i++) {
+ result.append('\n');
+ result.append(value[i]);
+ }
+ }
+ }
+
}
\ No newline at end of file