int (@NotNull CharSequence buffer, @NotNull CharSequence pattern, int fromIndex, int toIndex) { int patternLength = pattern.length(); if (fromIndex < 0) { fromIndex = 0; } int limit = toIndex - patternLength + 1; SearchLoop: for (int i = fromIndex; i < limit; i++) { for (int j = 0; j < patternLength; j++) { if (pattern.charAt(j) != buffer.charAt(i + j)) continue SearchLoop; } return i; } return -1; }