mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Ignore UTF byte order mark when parsing result
git-svn-id: https://zxing.googlecode.com/svn/trunk@2228 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
7399f24735
commit
9f45bab33c
|
@ -33,7 +33,7 @@ public final class AddressBookAUResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
// MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
|
||||
if (!rawText.contains("MEMORY") || !rawText.contains("\r\n")) {
|
||||
return null;
|
||||
|
|
|
@ -37,7 +37,7 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
|||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("MECARD:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
|||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("BIZCARD:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public final class EmailAddressResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
String emailAddress;
|
||||
if (rawText.startsWith("mailto:") || rawText.startsWith("MAILTO:")) {
|
||||
// If it starts with mailto:, assume it is definitely trying to be an email address
|
||||
|
|
|
@ -33,7 +33,7 @@ public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
|||
|
||||
@Override
|
||||
public EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("MATMSG:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public final class ExpandedProductResultParser extends ResultParser {
|
|||
return null;
|
||||
}
|
||||
// Really neither of these should happen:
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (rawText == null) {
|
||||
// ExtendedProductParsedResult NOT created. Input text is NULL
|
||||
return null;
|
||||
|
|
|
@ -36,11 +36,7 @@ public final class GeoResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public GeoParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String rawText = getMassagedText(result);
|
||||
Matcher matcher = GEO_URL_PATTERN.matcher(rawText);
|
||||
if (!matcher.matches()) {
|
||||
return null;
|
||||
|
|
|
@ -35,7 +35,7 @@ public final class ISBNResultParser extends ResultParser {
|
|||
if (format != BarcodeFormat.EAN_13) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
int length = rawText.length();
|
||||
if (length != 13) {
|
||||
return null;
|
||||
|
|
|
@ -35,7 +35,7 @@ public final class ProductResultParser extends ResultParser {
|
|||
format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
int length = rawText.length();
|
||||
for (int x = 0; x < length; x++) {
|
||||
char c = rawText.charAt(x);
|
||||
|
|
|
@ -65,6 +65,7 @@ public abstract class ResultParser {
|
|||
private static final Pattern ALPHANUM = Pattern.compile("[a-zA-Z0-9]*");
|
||||
private static final Pattern AMPERSAND = Pattern.compile("&");
|
||||
private static final Pattern EQUALS = Pattern.compile("=");
|
||||
private static final String BYTE_ORDER_MARK = "\ufeff";
|
||||
|
||||
/**
|
||||
* Attempts to parse the raw {@link Result}'s contents as a particular type
|
||||
|
@ -73,6 +74,14 @@ public abstract class ResultParser {
|
|||
*/
|
||||
public abstract ParsedResult parse(Result theResult);
|
||||
|
||||
protected static String getMassagedText(Result result) {
|
||||
String text = result.getText();
|
||||
if (text.startsWith(BYTE_ORDER_MARK)) {
|
||||
text = text.substring(1);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static ParsedResult parseResult(Result theResult) {
|
||||
for (ResultParser parser : PARSERS) {
|
||||
ParsedResult result = parser.parse(theResult);
|
||||
|
|
|
@ -42,7 +42,7 @@ public final class SMSMMSResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public SMSParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("sms:") || rawText.startsWith("SMS:") ||
|
||||
rawText.startsWith("mms:") || rawText.startsWith("MMS:"))) {
|
||||
return null;
|
||||
|
|
|
@ -32,7 +32,7 @@ public final class SMSTOMMSTOResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public SMSParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
|
||||
rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:"))) {
|
||||
return null;
|
||||
|
|
|
@ -30,7 +30,7 @@ public final class SMTPResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("smtp:") || rawText.startsWith("SMTP:"))) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public final class TelResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public TelParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("tel:") && !rawText.startsWith("TEL:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public final class URIResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
// We specifically handle the odd "URL" scheme here for simplicity
|
||||
if (rawText.startsWith("URL:")) {
|
||||
rawText = rawText.substring(4);
|
||||
|
|
|
@ -29,7 +29,7 @@ public final class URLTOResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("urlto:") && !rawText.startsWith("URLTO:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public final class VCardResultParser extends ResultParser {
|
|||
// Although we should insist on the raw text ending with "END:VCARD", there's no reason
|
||||
// to throw out everything else we parsed just because this was omitted. In fact, Eclair
|
||||
// is doing just that, and we can't parse its contacts without this leniency.
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
Matcher m = BEGIN_VCARD.matcher(rawText);
|
||||
if (!m.find() || m.start() != 0) {
|
||||
return null;
|
||||
|
|
|
@ -30,10 +30,7 @@ public final class VEventResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public CalendarParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
String rawText = getMassagedText(result);
|
||||
int vEventStart = rawText.indexOf("BEGIN:VEVENT");
|
||||
if (vEventStart < 0) {
|
||||
return null;
|
||||
|
|
|
@ -31,7 +31,7 @@ public final class WifiResultParser extends ResultParser {
|
|||
|
||||
@Override
|
||||
public WifiParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("WIFI:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue