1package com.android.mail.utils;
2
3import android.support.v4.text.BidiFormatter;
4
5/**
6 * A small utility class for working with strings.
7 */
8public class StringUtils {
9
10    /**
11     * Returns a string containing the tokens joined by delimiters.
12     * Additionally, each token is first passed through {@link BidiFormatter#unicodeWrap(String)}
13     * before appending to the string.
14     */
15    public static String joinAndBidiFormat(String delimiter, Iterable<String> tokens) {
16        return joinAndBidiFormat(delimiter, tokens, BidiFormatter.getInstance());
17    }
18
19    /**
20     * Returns a string containing the tokens joined by delimiters.
21     * Additionally, each token is first passed through {@link BidiFormatter#unicodeWrap(String)}
22     * before appending to the string.
23     */
24    public static String joinAndBidiFormat(
25            String delimiter, Iterable<String> tokens, BidiFormatter bidiFormatter) {
26        final StringBuilder sb = new StringBuilder();
27        boolean firstTime = true;
28        for (String token : tokens) {
29            if (firstTime) {
30                firstTime = false;
31            } else {
32                sb.append(delimiter);
33            }
34            sb.append(bidiFormatter.unicodeWrap(token));
35        }
36        return sb.toString();
37    }
38}
39