Commit 1abe1e37 authored by rhi's avatar rhi 🐑
Browse files

Drop empty string components from formatted postal addresses

parent e8a3a484
......@@ -43,6 +43,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
......@@ -1075,8 +1076,8 @@ public class AndroidContact {
*/
String formattedAddress = address.getLabel();
if (TextUtils.isEmpty(formattedAddress)) {
String lineStreet = StringUtils.join(new String[] { address.getStreetAddress(), address.getPoBox(), address.getExtendedAddress() }, " "),
lineLocality = StringUtils.join(new String[]{ address.getPostalCode(), address.getLocality() }, " ");
String lineStreet = StringUtils.join(dropEmpty(new String[] { address.getStreetAddress(), address.getPoBox(), address.getExtendedAddress() }), " "),
lineLocality = StringUtils.join(dropEmpty(new String[] { address.getPostalCode(), address.getLocality() }), " ");
List<String> lines = new LinkedList<>();
if (!TextUtils.isEmpty(lineStreet))
......@@ -1283,6 +1284,14 @@ public class AndroidContact {
}
protected static String[] dropEmpty(String[] strings) {
ArrayList<String> list = new ArrayList<>(strings.length);
for (String s : strings)
if (!StringUtils.isEmpty(s))
list.add(s);
return list.toArray(new String[list.size()]);
}
protected static String labelToXName(String label) {
return "X-" + label.replaceAll(" ","_").replaceAll("[^\\p{L}\\p{Nd}\\-_]", "").toUpperCase(Locale.US);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment