/** 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 lastIndexOf(@NonNull CharSequence sequence, char c) { return lastIndexOf(sequence, c, sequence.length()); }
public static boolean regionMatches( @NonNull CharSequence sequence, boolean ignoreCase, int thisStart, @NonNull CharSequence string, int start, int length) { if (!ignoreCase) { return regionMatches(sequence, thisStart, string, start, length); } if (thisStart < 0 || length > sequence.length() - thisStart) { return false; } if (start < 0 || length > string.length() - start) { return false; } int end = thisStart + length; while (thisStart < end) { char c1 = sequence.charAt(thisStart++); char c2 = string.charAt(start++); if (c1 != c2 && foldCase(c1) != foldCase(c2)) { return false; } } return true; }
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 lineStart = lastIndexOf(contents, '\n', index); if (lineStart == -1) { lineStart = 0; int end = indexOf(contents, patternEnd, offset + patternStart.length()); if (end != -1) { return new Location(file, new DefaultPosition(line, column, index), if (hints.isConstructor() && startsWith(contents, SUPER_KEYWORD, index)) { patternStart = SUPER_KEYWORD;
int offset = 0; while (true) { offset = indexOf(source, '\n', offset); if (offset == -1 || offset == length - 1) { break; char peek = source.charAt(offset); if (peek == '<' || peek == '=' || peek == '>') { if (startsWith(source, "<<<<<<< ", offset) || startsWith(source, "=======\n", offset) || startsWith(source, ">>>>>>> ", offset)) { Location location = Location.create(context.file, source, offset, offset + 7); context.report(ISSUE, location, "Missing merge marker?");
@NonNull File manifest) { CharSequence xml = client.readFile(manifest); Document document = CharSequences.parseDocumentSilently(xml, true); if (document == null) { return;
@Nullable public static Document parseDocumentSilently(@NonNull CharSequence xml, boolean namespaceAware) { try { Reader reader = getReader(xml, true); return XmlUtils.parseDocument(reader, namespaceAware); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }
public static boolean startsWith(@NonNull CharSequence sequence, @NonNull CharSequence prefix) { return startsWith(sequence, prefix, 0); }
private static int findPrefixOnPreviousLine(CharSequence contents, int lineStart, String prefix) { // Search backwards on the previous line until you find the prefix start (also look // back on previous lines if the previous line(s) contain just whitespace char first = prefix.charAt(0); int offset = lineStart - 2; // 0: first char on this line, -1: \n on previous line, -2 last boolean seenNonWhitespace = false; for (; offset >= 0; offset--) { char c = contents.charAt(offset); if (seenNonWhitespace && c == '\n') { return -1; } if (!seenNonWhitespace && !Character.isWhitespace(c)) { seenNonWhitespace = true; } if (c == first && CharSequences.regionMatches(contents, offset, prefix, 0, prefix.length())) { return offset; } } return -1; } }
public static EcjSourceFile create(@NonNull CharSequence source, @NonNull File file, @NonNull String encoding) { char[] contents = CharSequences.getCharArray(source); return new EcjSourceFile(contents, file.getPath(), encoding, file); }
return CharSequences.createSequence(array, 0, size); } catch (CharacterCodingException ignore) {
@Nullable private Multimap<String, String> getIdToTagsIn(@NonNull Context context, @NonNull File file) { if (!file.getPath().endsWith(DOT_XML)) { return null; } if (mFileIdMap == null) { mFileIdMap = Maps.newHashMap(); } Multimap<String, String> map = mFileIdMap.get(file); if (map == null) { map = ArrayListMultimap.create(); mFileIdMap.put(file, map); CharSequence xml = context.getClient().readFile(file); // TODO: Use pull parser instead for better performance! // See LayoutInflationDetector#hasLayoutParams for an example Document document = CharSequences.parseDocumentSilently(xml, true); if (document != null && document.getDocumentElement() != null) { addViewTags(map, document.getDocumentElement()); } } return map; }
try { CharSequence s = client.readFile(file); Reader reader = CharSequences.getReader(s, true); if (hasLayoutParams(reader)) { return true;
private static boolean isMatch(@NonNull CharSequence contents, int offset, String pattern, @Nullable SearchHints hints) { if (!startsWith(contents, pattern, offset)) { return false;
if (prev == '\\') { if (c == 'u' || c == 'U') { if (regionMatches(source,true, i - 1, ESCAPE_STRING, 0, ESCAPE_STRING.length())) { String message = regionMatches(source, i - 1, STOPSHIP_COMMENT, 0, STOPSHIP_COMMENT.length())) {
public static int lastIndexOf(@NonNull CharSequence haystack, @NonNull String needle) { return lastIndexOf(haystack, needle, haystack.length()); }
if (classpathFile.exists()) { CharSequence classpathXml = readFile(classpathFile); Document document = CharSequences.parseDocumentSilently(classpathXml, false); if (document != null) { NodeList tags = document.getElementsByTagName("classpathentry");
public static int indexOf(@NonNull CharSequence sequence, char c) { return indexOf(sequence, c, 0); }
public static int lastIndexOf(@NonNull CharSequence haystack, @NonNull String needle, int start) { int length = haystack.length(); int needleLength = needle.length(); if (needleLength <= length && start >= 0) { if (needleLength > 0) { if (start > length - needleLength) { start = length - needleLength; } char firstChar = needle.charAt(0); while (true) { int i = lastIndexOf(haystack, firstChar, start); if (i == -1) { return -1; } int o1 = i, o2 = 0; //noinspection StatementWithEmptyBody while (++o2 < needleLength && haystack.charAt(++o1) == needle.charAt(o2)) { } if (o2 == needleLength) { return i; } start = i - 1; } } return start < length ? start : length; } return -1; }