mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
MECARD TEL should have only digits
git-svn-id: https://zxing.googlecode.com/svn/trunk@2714 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ff1ecd9700
commit
93b0774aac
|
@ -37,6 +37,7 @@ final class MECARDContactEncoder extends ContactEncoder {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final char TERMINATOR = ';';
|
private static final char TERMINATOR = ';';
|
||||||
|
private static final Pattern NOT_DIGITS = Pattern.compile("[^0-9]+");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] encode(Iterable<String> names,
|
public String[] encode(Iterable<String> names,
|
||||||
|
@ -60,7 +61,7 @@ final class MECARDContactEncoder extends ContactEncoder {
|
||||||
appendUpToUnique(newContents, newDisplayContents, "TEL", phones, Integer.MAX_VALUE, new Formatter() {
|
appendUpToUnique(newContents, newDisplayContents, "TEL", phones, Integer.MAX_VALUE, new Formatter() {
|
||||||
@Override
|
@Override
|
||||||
public String format(String source) {
|
public String format(String source) {
|
||||||
return PhoneNumberUtils.formatNumber(source);
|
return keepOnlyDigits(PhoneNumberUtils.formatNumber(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
appendUpToUnique(newContents, newDisplayContents, "EMAIL", emails, Integer.MAX_VALUE, null);
|
appendUpToUnique(newContents, newDisplayContents, "EMAIL", emails, Integer.MAX_VALUE, null);
|
||||||
|
@ -70,6 +71,10 @@ final class MECARDContactEncoder extends ContactEncoder {
|
||||||
return new String[] { newContents.toString(), newDisplayContents.toString() };
|
return new String[] { newContents.toString(), newDisplayContents.toString() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String keepOnlyDigits(CharSequence s) {
|
||||||
|
return s == null ? null : NOT_DIGITS.matcher(s).replaceAll("");
|
||||||
|
}
|
||||||
|
|
||||||
private static void append(StringBuilder newContents,
|
private static void append(StringBuilder newContents,
|
||||||
StringBuilder newDisplayContents,
|
StringBuilder newDisplayContents,
|
||||||
String prefix,
|
String prefix,
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class ContactInfoGenerator implements GeneratorSource {
|
||||||
output.append("MECARD:");
|
output.append("MECARD:");
|
||||||
maybeAppendMECARD(output, "N", name.replace(",", ""));
|
maybeAppendMECARD(output, "N", name.replace(",", ""));
|
||||||
maybeAppendMECARD(output, "ORG", company);
|
maybeAppendMECARD(output, "ORG", company);
|
||||||
maybeAppendMECARD(output, "TEL", tel);
|
maybeAppendMECARD(output, "TEL", keepOnlyDigits(tel));
|
||||||
maybeAppendMECARD(output, "URL", url);
|
maybeAppendMECARD(output, "URL", url);
|
||||||
maybeAppendMECARD(output, "EMAIL", email);
|
maybeAppendMECARD(output, "EMAIL", email);
|
||||||
maybeAppendMECARD(output, "ADR", buildAddress(address, address2));
|
maybeAppendMECARD(output, "ADR", buildAddress(address, address2));
|
||||||
|
@ -111,6 +111,10 @@ public final class ContactInfoGenerator implements GeneratorSource {
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String keepOnlyDigits(String s) {
|
||||||
|
return s == null ? null : s.replaceAll("[^0-9]+", "");
|
||||||
|
}
|
||||||
|
|
||||||
private static String buildAddress(String address, String address2) {
|
private static String buildAddress(String address, String address2) {
|
||||||
if (!address.isEmpty()) {
|
if (!address.isEmpty()) {
|
||||||
if (!address2.isEmpty()) {
|
if (!address2.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue