Search in sources :

Example 66 with StringTokenizer

use of java.util.StringTokenizer in project android_frameworks_base by ParanoidAndroid.

the class UrlQuerySanitizer method parseQuery.

/**
     * Parse a query. A query string is any number of parameter-value clauses
     * separated by any non-zero number of ampersands. A parameter-value clause
     * is a parameter followed by an equal sign, followed by a value. If the
     * equal sign is missing, the value is assumed to be the empty string.
     * @param query the query to parse.
     */
public void parseQuery(String query) {
    clear();
    // Split by '&'
    StringTokenizer tokenizer = new StringTokenizer(query, "&");
    while (tokenizer.hasMoreElements()) {
        String attributeValuePair = tokenizer.nextToken();
        if (attributeValuePair.length() > 0) {
            int assignmentIndex = attributeValuePair.indexOf('=');
            if (assignmentIndex < 0) {
                // No assignment found, treat as if empty value
                parseEntry(attributeValuePair, "");
            } else {
                parseEntry(attributeValuePair.substring(0, assignmentIndex), attributeValuePair.substring(assignmentIndex + 1));
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 67 with StringTokenizer

use of java.util.StringTokenizer in project generator by mybatis.

the class Ibatis2FormattingUtilities method escapeStringForIbatis2.

/**
     * Escape string for ibatis2.
     *
     * @param s
     *            the s
     * @return the string
     */
public static String escapeStringForIbatis2(String s) {
    //$NON-NLS-1$
    StringTokenizer st = new StringTokenizer(s, "$#", true);
    StringBuilder sb = new StringBuilder();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if ("$".equals(token)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            sb.append("$$");
        } else if ("#".equals(token)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            sb.append("##");
        } else {
            sb.append(token);
        }
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 68 with StringTokenizer

use of java.util.StringTokenizer in project mybatis-3 by mybatis.

the class BaseJdbcLogger method removeBreakingWhitespace.

protected String removeBreakingWhitespace(String original) {
    StringTokenizer whitespaceStripper = new StringTokenizer(original);
    StringBuilder builder = new StringBuilder();
    while (whitespaceStripper.hasMoreTokens()) {
        builder.append(whitespaceStripper.nextToken());
        builder.append(" ");
    }
    return builder.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 69 with StringTokenizer

use of java.util.StringTokenizer in project neo4j by neo4j.

the class TextUtil method tokenizeStringWithQuotes.

/**
     * Tokenizes a string, regarding quotes. Examples:
     *
     * o '"One two"'              ==&gt; [ "One two" ]
     * o 'One two'                ==&gt; [ "One", "two" ]
     * o 'One "two three" four'   ==&gt; [ "One", "two three", "four" ]
     *
     * @param string the string to tokenize.
     * @param trim  whether or not to trim each token.
     * @return the tokens from the line.
     */
public static String[] tokenizeStringWithQuotes(String string, boolean trim) {
    if (trim) {
        string = string.trim();
    }
    ArrayList<String> result = new ArrayList<String>();
    string = string.trim();
    boolean inside = string.startsWith("\"");
    StringTokenizer quoteTokenizer = new StringTokenizer(string, "\"");
    while (quoteTokenizer.hasMoreTokens()) {
        String token = quoteTokenizer.nextToken();
        if (trim) {
            token = token.trim();
        }
        if (token.length() == 0) {
        // Skip it
        } else if (inside) {
            // Don't split
            result.add(token);
        } else {
            Collections.addAll(result, TextUtil.splitAndKeepEscapedSpaces(token, false));
        }
        inside = !inside;
    }
    return result.toArray(new String[result.size()]);
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList)

Example 70 with StringTokenizer

use of java.util.StringTokenizer in project generator by mybatis.

the class StringUtility method escapeStringForXml.

public static String escapeStringForXml(String s) {
    //$NON-NLS-1$
    StringTokenizer st = new StringTokenizer(s, "\"", true);
    StringBuilder sb = new StringBuilder();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if ("\"".equals(token)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            sb.append("&quot;");
        } else {
            sb.append(token);
        }
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Aggregations

StringTokenizer (java.util.StringTokenizer)4881 ArrayList (java.util.ArrayList)1083 IOException (java.io.IOException)506 File (java.io.File)392 BufferedReader (java.io.BufferedReader)380 HashMap (java.util.HashMap)375 HashSet (java.util.HashSet)263 FileReader (java.io.FileReader)224 List (java.util.List)200 InputStreamReader (java.io.InputStreamReader)191 Map (java.util.Map)152 FileInputStream (java.io.FileInputStream)135 Iterator (java.util.Iterator)114 Set (java.util.Set)114 URL (java.net.URL)108 NoSuchElementException (java.util.NoSuchElementException)90 Properties (java.util.Properties)84 InputStream (java.io.InputStream)83 BufferedWriter (java.io.BufferedWriter)80 FileNotFoundException (java.io.FileNotFoundException)78