boolean (List<? extends TextRange> ranges, int startIndex, int endIndex, int offset) { if (endIndex < startIndex || ranges.size() <= startIndex || ranges.size() <= endIndex) return false; int startOffset = ranges.get(startIndex).getStartOffset(); int endOffset = ranges.get(endIndex).getEndOffset(); if (offset < startOffset || offset > endOffset) return false; if (startIndex == endIndex) return true; int midIndex = (endIndex + startIndex) / 2; return rangesContain(ranges, startIndex, midIndex, offset) || rangesContain(ranges, midIndex + 1, endIndex, offset); }