/** Look up the contents of the given line */ static int getLineOffset(CharSequence contents, int line) { int index = 0; for (int i = 0; i < line; i++) { index = indexOf(contents, '\n', index); if (index == -1) { return -1; } index++; } return index; }
public static int indexOf(@NonNull CharSequence haystack, CharSequence needle) { return indexOf(haystack, needle, 0); }
public static int indexOf(@NonNull CharSequence sequence, char c) { return indexOf(sequence, c, 0); }
public static int indexOf(@NonNull CharSequence haystack, CharSequence needle, int start) { int needleLength = needle.length(); if (needleLength == 0) { return start; } char first = needle.charAt(0); if (needleLength == 1) { return indexOf(haystack, first); } search: for (int i = start, max = haystack.length() - needleLength; i <= max; i++) { if (haystack.charAt(i) == first) { for (int h = i + 1, n = 1; n < needleLength; h++, n++) { if (haystack.charAt(h) != needle.charAt(n)) { continue search; } } return i; } } return -1; }
/** Returns whether this file contains any suppress comment markers */ public boolean containsCommentSuppress() { if (containsCommentSuppress == null) { containsCommentSuppress = false; String prefix = getSuppressCommentPrefix(); if (prefix != null) { CharSequence contents = getContents(); if (contents != null) { containsCommentSuppress = indexOf(contents, prefix) != -1; } } } return containsCommentSuppress; }
private static int findNextMatch(@NonNull CharSequence contents, int offset, String pattern, @Nullable SearchHints hints) { int constructorIndex = -1; if (hints != null && hints.isConstructor()) { // Special condition: See if the call is referenced as "super" instead. assert hints.isWholeWord(); int index = indexOf(contents, SUPER_KEYWORD, offset); if (index != -1 && isMatch(contents, index, SUPER_KEYWORD, hints)) { constructorIndex = index; } } int loopIncrement = Math.max(1, pattern.length()); while (true) { int index = indexOf(contents, pattern, offset); if (index == -1 || index == contents.length()) { return constructorIndex; } else { if (isMatch(contents, index, pattern, hints)) { if (constructorIndex != -1) { return Math.min(constructorIndex, index); } return index; } else { offset = index + loopIncrement; } } } }
if (contents != null) { if (context.isEnabled(WRONG_KEEP)) { int index = indexOf(contents, int index = indexOf(contents, "-keep public class * extends android.app.Activity"); if (index != -1) { int i = indexOf(properties, PROGUARD_CONFIG); if (i == -1) { return; if (indexOf(properties, PROGUARD_CONFIG) != -1) { context.report(SPLIT_CONFIG, Location.create(context.file, contents, index, index),
int offset = 0; while (true) { offset = indexOf(source, '\n', offset); if (offset == -1 || offset == length - 1) { break;
private static Location refineLocation(Context context, Location location, String formatString, int substringStart, int substringEnd) { Position startLocation = location.getStart(); Position endLocation = location.getEnd(); if (startLocation != null && endLocation != null) { int startOffset = startLocation.getOffset(); int endOffset = endLocation.getOffset(); if (startOffset >= 0) { CharSequence contents = context.getClient().readFile(location.getFile()); if (endOffset <= contents.length() && startOffset < endOffset) { int formatOffset = indexOf(contents, formatString, startOffset); if (formatOffset != -1 && formatOffset <= endOffset) { return Location.create(location.getFile(), contents, formatOffset + substringStart, formatOffset + substringEnd); } } } } return location; }
int offset = 0; while (currentLine < line) { offset = indexOf(contents, '\n', offset); if (offset == -1) { return create(file); line = adjustLine(contents, line, offset, index); } else if (direction == SearchDirection.EOL_BACKWARD) { int lineEnd = indexOf(contents, '\n', offset); if (lineEnd == -1) { lineEnd = contents.length(); direction == SearchDirection.EOL_NEAREST; int lineEnd = indexOf(contents, '\n', offset); if (lineEnd == -1) { lineEnd = contents.length(); int end = indexOf(contents, patternEnd, offset + patternStart.length()); if (end != -1) { return new Location(file, new DefaultPosition(line, column, index),
File file = currentFiles.get(0); CharSequence contents = context.getClient().readFile(file); int firstLineEnd = indexOf(contents, '\n'); if (firstLineEnd == -1) { firstLineEnd = contents.length();