+ * @param unicode
+ * allow Uniode or only ASCII characters
+ *
+ * @return the {@link String} representation
+ */
+ public String[] toStringArray(String format, String separator,
+ String padding, int width, boolean unicode) {
+ if (width > -1) {
+ int numOfFields = format.split("\\|").length;
+ if (separator != null)
+ width -= (numOfFields - 1) * separator.length();
+ if (padding != null)
+ width -= (numOfFields) * (2 * padding.length());
+
+ if (width < 0)
+ width = 0;
+ }
+
+ List<String> str = new LinkedList<String>();
+
+ boolean first = true;
+ for (String s : toStringArray(format, width, unicode)) {
+ if (!first) {
+ str.add(separator);
+ }
+
+ if (padding != null)
+ str.add(padding + s + padding);
+ else
+ str.add(s);
+
+ first = false;
+ }
+
+ return str.toArray(new String[] {});
+ }
+
+ /**
+ * Return a {@link String} representation of this contact formated
+ * accordingly to the given format, part by part.
+ *
+ * <p>
+ * The format is basically a list of field names separated by a pipe and
+ * optionally parametrised. The parameters allows you to:
+ * <ul>
+ * <li>@x: show only a present/not present info</li>
+ * <li>@n: limit the size to a fixed value 'n'</li>
+ * <li>@+: expand the size of this field as much as possible</li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * In case of lists or multiple-fields values, you can select a specific
+ * list or field with:
+ * <ul>
+ * <li>FIELD@(0): select the first value in a list</li>
+ * <li>FIELD@[1]: select the second field in a multiple-fields value</li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * You can also add a fixed text if it starts with a simple-quote (').
+ * </p>
+ *
+ * <p>
+ * Example: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x"
+ * </p>
+ *
+ * @param format
+ * the format to use
+ * @param width
+ * a fixed width or -1 for "as long as needed"
+ * @param unicode
+ * allow Uniode or only ASCII characters
+ *