Java String Quote quotedIndexOf(String text, int start, int limit, String setOfChars)

Here you can find the source of quotedIndexOf(String text, int start, int limit, String setOfChars)

Description

Returns the index of the first character in a set, ignoring quoted text.

License

Open Source License

Parameter

Parameter Description
text text to be searched
start the beginning index, inclusive; <code>0 <= start <= limit</code>.
limit the ending index, exclusive; <code>start <= limit <= text.length()</code>.
setOfChars string with one or more distinct characters

Return

Offset of the first character in setOfChars found, or -1 if not found.

Declaration

public static int quotedIndexOf(String text, int start, int limit,
        String setOfChars) 

Method Source Code

//package com.java2s;
// License & terms of use: http://www.unicode.org/copyright.html#License

public class Main {
    private static final char APOSTROPHE = '\'';
    private static final char BACKSLASH = '\\';

    /**//  w  w w . j  a  v a 2  s.  c o  m
     * Returns the index of the first character in a set, ignoring quoted text.
     * For example, in the string "abc'hide'h", the 'h' in "hide" will not be
     * found by a search for "h".  Unlike String.indexOf(), this method searches
     * not for a single character, but for any character of the string
     * <code>setOfChars</code>.
     * @param text text to be searched
     * @param start the beginning index, inclusive; <code>0 <= start
     * <= limit</code>.
     * @param limit the ending index, exclusive; <code>start <= limit
     * <= text.length()</code>.
     * @param setOfChars string with one or more distinct characters
     * @return Offset of the first character in <code>setOfChars</code>
     * found, or -1 if not found.
     * @see String#indexOf
     */
    public static int quotedIndexOf(String text, int start, int limit,
            String setOfChars) {
        for (int i = start; i < limit; ++i) {
            char c = text.charAt(i);
            if (c == BACKSLASH) {
                ++i;
            } else if (c == APOSTROPHE) {
                while (++i < limit && text.charAt(i) != APOSTROPHE) {
                }
            } else if (setOfChars.indexOf(c) >= 0) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. quoted(String text)
  2. quoted(String val, boolean wrap)
  3. quoted(String value)
  4. quoted(String value, boolean addQuotes)
  5. quotedEscape(final String string)
  6. quotedJavaChar(char c, StringBuilder b)
  7. quotedName(String name)
  8. quotedName(String name)
  9. quotedName(String name)