Here you can find the source of quotedIndexOf(String text, int start, int limit, String setOfChars)
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 |
setOfChars
found, or -1 if not found.
public static int quotedIndexOf(String text, int start, int limit, String setOfChars)
//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; } }