Java Code Examples for android.text.TextUtils#StringSplitter

The following examples show how to use android.text.TextUtils#StringSplitter . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Takes a flattened string of parameters and adds each one to
 * this Parameters object.
 * <p>The {@link #flatten()} method does the reverse.</p>
 *
 * @param flattened a String of parameters (key-value paired) that
 *                  are semi-colon delimited
 */
public void unflatten(String flattened) {
    mMap.clear();

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
    splitter.setString(flattened);
    for (String kv : splitter) {
        int pos = kv.indexOf('=');
        if (pos == -1) {
            continue;
        }
        String k = kv.substring(0, pos);
        String v = kv.substring(pos + 1);
        mMap.put(k, v);
    }
}
 
Example 2
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ArrayList<String> split(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<String> substrings = new ArrayList<String>();
    for (String s : splitter) {
        substrings.add(s);
    }
    return substrings;
}
 
Example 3
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ArrayList<Integer> splitInt(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<Integer> substrings = new ArrayList<Integer>();
    for (String s : splitter) {
        substrings.add(Integer.parseInt(s));
    }
    if (substrings.size() == 0) return null;
    return substrings;
}
 
Example 4
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void splitInt(String str, int[] output) {
    if (str == null) return;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    int index = 0;
    for (String s : splitter) {
        output[index++] = Integer.parseInt(s);
    }
}
 
Example 5
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void splitFloat(String str, float[] output) {
    if (str == null) return;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    int index = 0;
    for (String s : splitter) {
        output[index++] = Float.parseFloat(s);
    }
}
 
Example 6
Source File: Camera.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ArrayList<Size> splitSize(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<Size> sizeList = new ArrayList<Size>();
    for (String s : splitter) {
        Size size = strToSize(s);
        if (size != null) sizeList.add(size);
    }
    if (sizeList.size() == 0) return null;
    return sizeList;
}
 
Example 7
Source File: Camera.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
private void unFlatten(int cameraId, String flatten) {
    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
    splitter.setString(flatten);
    HashMap<String, String> map = new HashMap<>();
    for (String kv : splitter) {
        int pos = kv.indexOf('=');
        if (pos == -1) continue;
        String k = kv.substring(0, pos);
        String v = kv.substring(pos + 1);
        map.put(k, v);
    }
    mSupportedModes.put(cameraId, map);
}
 
Example 8
Source File: Camera.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
private ArrayList<String> split(String str) {
    if (str == null) return null;

    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(str);
    ArrayList<String> substrings = new ArrayList<String>();
    for (String s : splitter) {
        substrings.add(s);
    }
    return substrings;
}
 
Example 9
Source File: UtteranceRewriter.java    From speechutils with Apache License 2.0 5 votes vote down vote up
public CommandHolder(String inputHeader, List<Command> commands) {
    boolean hasColumnUtterance = false;
    SortedMap<Integer, String> header = new TreeMap<>();
    List<String> fields = new ArrayList<>();
    if (inputHeader != null && !inputHeader.isEmpty()) {
        final TextUtils.StringSplitter COLUMN_SPLITTER = new TextUtils.SimpleStringSplitter('\t');
        COLUMN_SPLITTER.setString(inputHeader);
        int fieldCounter = 0;
        for (String columnName : COLUMN_SPLITTER) {
            fields.add(columnName);
            if (COLUMNS.contains(columnName)) {
                header.put(fieldCounter, columnName);
                if (HEADER_UTTERANCE.equals(columnName)) {
                    hasColumnUtterance = true;
                }
            }
            fieldCounter++;
        }
    }
    mCommands = commands;
    // If the Utterance column is missing then assume that the
    // input was without a header and interpret it as a one or two column table.
    if (!hasColumnUtterance) {
        if (fields.size() > 1) {
            mHeader = DEFAULT_HEADER_2;
            mCommands.add(0, new Command(fields.get(0), fields.get(1)));
        } else if (fields.size() > 0) {
            mHeader = DEFAULT_HEADER_1;
            mCommands.add(0, new Command(fields.get(0), ""));
        } else {
            mHeader = DEFAULT_HEADER_1;
        }
    } else {
        mHeader = header;
    }
}
 
Example 10
Source File: UtteranceRewriter.java    From speechutils with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a command based on the given fields.
 *
 * @param header         parsed header
 * @param line           single row
 * @param commandMatcher command matcher
 * @return command or null if commandMatcher rejects the command
 */
private static Command getCommand(SortedMap<Integer, String> header, String line, CommandMatcher commandMatcher) {
    String label = null;
    String comment = null;
    Pattern locale = null;
    Pattern service = null;
    Pattern app = null;
    Pattern utterance = null;
    String command = null;
    String replacement = null;
    String arg1 = null;
    String arg2 = null;

    final TextUtils.StringSplitter columnSplitter = new TextUtils.SimpleStringSplitter('\t');
    columnSplitter.setString(line);

    int i = 0;
    for (String split : columnSplitter) {
        String colName = header.get(i++);
        if (colName == null) {
            continue;
        }
        switch (colName) {
            case HEADER_LABEL:
                label = split.trim();
                break;
            case HEADER_COMMENT:
                comment = split.trim();
                break;
            case HEADER_LOCALE:
                locale = Pattern.compile(split.trim());
                break;
            case HEADER_SERVICE:
                service = Pattern.compile(split.trim());
                break;
            case HEADER_APP:
                app = Pattern.compile(split.trim());
                break;
            case HEADER_UTTERANCE:
                split = split.trim();
                if (split.isEmpty()) {
                    throw new IllegalArgumentException("Empty Utterance");
                }
                utterance = Pattern.compile(split, Constants.REWRITE_PATTERN_FLAGS);
                break;
            case HEADER_REPLACEMENT:
                replacement = Command.unescape(split);
                break;
            case HEADER_COMMAND:
                command = Command.unescape(split.trim());
                break;
            case HEADER_ARG1:
                arg1 = Command.unescape(split);
                break;
            case HEADER_ARG2:
                arg2 = Command.unescape(split);
                break;
            default:
                // Columns with undefined names are ignored
                break;
        }
    }

    if (commandMatcher != null && !commandMatcher.matches(locale, service, app)) {
        return null;
    }

    if (arg1 == null) {
        return new Command(label, comment, locale, service, app, utterance, replacement, command);
    }

    if (arg2 == null) {
        return new Command(label, comment, locale, service, app, utterance, replacement, command, new String[]{arg1});
    }

    return new Command(label, comment, locale, service, app, utterance, replacement, command, new String[]{arg1, arg2});
}