/*
Finds the index for all disjoint (non-overlapping) occurances of the substringToLookFor in the string.
351501
public static ArrayList<Integer> findDistinctIndexesOf( String string, String substringToLookFor )
  {
    ArrayList<Integer> positions = new ArrayList<Integer>();

    if( GosuStringUtil.isEmpty( substringToLookFor ) )
    {
      return positions;
    }

    int i = 0;
    i = GosuStringUtil.indexOf( string, substringToLookFor, i );
    while( i != -1 )
    {
      positions.add( i );
      i += substringToLookFor.length();
      i = GosuStringUtil.indexOf( string, substringToLookFor, i );
    }
    return positions;
  }
917604
def _get_next_occurrence(haystack, offset, needles):
        
        # make map of first char to full needle (only works if all needles
        # have different first characters)
        firstcharmap = dict([(n[0], n) for n in needles])
        firstchars = firstcharmap.keys()
        while offset < len(haystack):
            if haystack[offset] in firstchars:
                possible_needle = firstcharmap[haystack[offset]]
                if haystack[offset:offset + len(possible_needle)] == possible_needle:
                    return offset, possible_needle
            offset += 1
        return None
1251126
private static int ordinalIndexOf(final String str, final String substr, final int ordinal, final boolean isLastIndex) {
        if (ordinal < 1) {
            throw new IllegalArgumentException("ordinal(" + ordinal + ") must be >= 1");
        }

        if (N.isNullOrEmpty(str) || N.isNullOrEmpty(substr) || substr.length() > str.length()) {
            return N.INDEX_NOT_FOUND;
        }

        int fromIndex = isLastIndex ? str.length() : 0;

        for (int found = 0; fromIndex >= 0;) {
            fromIndex = isLastIndex ? str.lastIndexOf(substr, fromIndex) : str.indexOf(substr, fromIndex);

            if (fromIndex < 0) {
                return N.INDEX_NOT_FOUND;
            }

            if (++found >= ordinal) {
                break;
            }

            fromIndex = isLastIndex ? (fromIndex - substr.length()) : (fromIndex + substr.length());
        }

        return fromIndex;
    }
1292120
private static boolean substringStartsWith(String string, int offset, String substring) {
    return string.regionMatches(offset, substring, 0, substring.length());
  }
1233370
public static int indexOf(ByteBuf needle, ByteBuf haystack) {
        // TODO: maybe use Boyer Moore for efficiency.
        int attempts = haystack.readableBytes() - needle.readableBytes() + 1;
        for (int i = 0; i < attempts; i++) {
            if (equals(needle, needle.readerIndex(),
                       haystack, haystack.readerIndex() + i,
                       needle.readableBytes())) {
                return haystack.readerIndex() + i;
            }
        }
        return -1;
    }
862041
public static int indexOf( String text , String needle , int fromIndex , boolean ignoreCase )
    {
        if (ignoreCase)
            return indexOfIgnoreCase(text,needle,fromIndex);
        else
            return text.indexOf(needle,fromIndex);
    }
1026544
public static int nthIndexOf(final String string, final String token,
            final int index)
   {
      int j = 0;

      for (int i = 0; i < index; i++)
      {
         j = string.indexOf(token, j + 1);
         if (j == -1)
            break;
      }

      return j;
   }
1180855
def substring_search(query, list_of_strings, limit_results=DEFAULT_LIMIT):
    

    matching = []

    query_words = query.split(' ')

    # sort by longest word (higest probability of not finding a match)
    query_words.sort(key=len, reverse=True)

    counter = 0

    for s in list_of_strings:

        target_words = s.split(' ')

        # the anyword searching function is separate
        if(anyword_substring_search(target_words, query_words)):
            matching.append(s)

            # limit results
            counter += 1
            if(counter == limit_results):
                break

    return matching
737768
public static int indexOfIgnoreCase( String text , String needle , int fromIndex )
    {
        int textLen = text.length();
        int needleLen = needle.length();
        
        if (fromIndex >= textLen) return needleLen == 0 ? textLen : -1;
        int i = fromIndex;
        if (i < 0)
        	i = 0;
        if (needleLen == 0) return i;
        
        char first = Character.toUpperCase(needle.charAt(0));
        int max = textLen - needleLen;
        
        startSearchForFirstChar:
        while (true)
        {
            // Look for first character.
            while (i <= max)
            {
                char c = Character.toUpperCase(text.charAt(i));
                if (c != first)
                    i++;
                else
                    break;
            }
            if (i > max) return -1;
            
            // Found first character, now look at the rest of the string
            int j = i + 1;
            int end = j + needleLen - 1;
            int k = 1;
            while (j < end) 
            {
                char c1 = Character.toUpperCase(text.charAt(j++));
                char c2 = Character.toUpperCase(needle.charAt(k++));
                if (c1 != c2) 
                {
                    i++;
                    // Look for str's first char again.
                    continue startSearchForFirstChar;
                }
             }
            
            return i;
        }
    }
133071
private boolean doesModulePathIncludeSubstring(ModuleNode moduleNode, final String substring) {

        if (moduleNode == null) {
            return false;
        }

        boolean substringFoundInDescription = false;
        String commandObjectModuleDescription = moduleNode.getDescription();
        if (commandObjectModuleDescription != null) {
            substringFoundInDescription = commandObjectModuleDescription.contains(substring);
        }
        return substringFoundInDescription;
    }
401674
private int indexOf(ByteBuf haystack, byte[] needle) {
		for (int i = haystack.readerIndex(); i < haystack.writerIndex(); i++) {
			int haystackIndex = i;
			int needleIndex;
			for (needleIndex = 0; needleIndex < needle.length; needleIndex++) {
				if (haystack.getByte(haystackIndex) != needle[needleIndex]) {
					break;
				} else {
					haystackIndex++;
					if (haystackIndex == haystack.writerIndex() &&
							needleIndex != needle.length - 1) {
						return -1;
					}
				}
			}

			if (needleIndex == needle.length) {
				// Found the needle from the haystack!
				return i - haystack.readerIndex();
			}
		}
		return -1;
	}
634265
def get_string_index_oid(self, s):
        """"""
        return (len(self.get_bytes(s)), ) + self.get_bytes(s)
389235
public StringGrabber substring(int startIdx, int endIndex) {
		if (startIdx < 0) {
			startIdx = 0;
		}
		if (endIndex > length() - 1) {
			endIndex = length() - 1;
		}

		sb = new StringBuilder(substringInternally(startIdx, endIndex));
		return StringGrabber.this;
	}
1286756
@Private Location lookup(int index) {
    int size = lineBreakIndices.size();
    if (size == 0) return location(0, index);
    int lineNumber = binarySearch(lineBreakIndices, index);
    if (lineNumber == 0) return location(0, index);
    int previousBreak = lineBreakIndices.get(lineNumber - 1);
    return location(lineNumber, index - previousBreak - 1);
  }
302289
private static int jsSplitMatch(String stringValue, int startIndex,
                                  String separator) {

    if (startIndex + separator.length() > stringValue.length()) {
      return -1;
    }

    int matchIndex = stringValue.indexOf(separator, startIndex);

    if (matchIndex < 0) {
      return -1;
    }

    return matchIndex;
  }
313421
function substringPlacement( $startOffset, $endOffset, $totalStringLength )
    {
        $leftText = false;
        $rightText = false;

        if ( $startOffset > 0 )
            $leftText = true;

        if ( $endOffset < $totalStringLength-1 )
            $rightText = true;

        return array( 'hasTextLeft' => $leftText,
                      'hasTextRight' => $rightText );
    }
1177668
private Node tryFoldStringIndexOf(
      Node n, String functionName, Node lstringNode, Node firstArg) {
    checkArgument(n.isCall());
    checkArgument(lstringNode.isString());

    String lstring = NodeUtil.getStringValue(lstringNode);
    boolean isIndexOf = functionName.equals("indexOf");
    Node secondArg = firstArg.getNext();
    String searchValue = NodeUtil.getStringValue(firstArg);
    // searchValue must be a valid string.
    if (searchValue == null) {
      return n;
    }
    int fromIndex = isIndexOf ? 0 : lstring.length();
    if (secondArg != null) {
      // Third-argument and non-numeric second arg are problematic. Discard.
      if (secondArg.getNext() != null || !secondArg.isNumber()) {
        return n;
      } else {
        fromIndex = (int) secondArg.getDouble();
      }
    }
    int indexVal = isIndexOf ? lstring.indexOf(searchValue, fromIndex)
                             : lstring.lastIndexOf(searchValue, fromIndex);
    Node newNode = IR.number(indexVal);
    n.replaceWith(newNode);
    reportChangeToEnclosingScope(newNode);

    return newNode;
  }