@NonNull
    public List<Span> getSpans(int start, int end) {

        final int length = length();

        if (!isPositionValid(length, start, end)) {
            // we might as well throw here
            return Collections.emptyList();
        }

        // all requested
        if (start == 0
                && length == end) {
            // but also copy (do not allow external modification)
            final List<Span> list = new ArrayList<>(spans);
            Collections.reverse(list);
            return Collections.unmodifiableList(list);
        }

        final List<Span> list = new ArrayList<>(0);

        final Iterator<Span> iterator = spans.descendingIterator();
        Span span;

        while (iterator.hasNext()) {
            span = iterator.next();
            // we must execute 2 checks: if overlap with specified range or fully include it
            // if span.start is >= range.start -> check if it's before range.end
            // if span.end is <= end -> check if it's after range.start
            if (
                    (span.start >= start && span.start < end)
                            || (span.end <= end && span.end > start)
                            || (span.start < start && span.end > end)) {
                list.add(span);
            }
        }

        return Collections.unmodifiableList(list);
    }
@NonNull
    public List<Span> getSpans(int start, int end) {

        final int length = length();

        if (!isPositionValid(length, start, end)) {
            
            return Collections.emptyList();
        }

        
        if (start == 0
                && length == end) {
            
            final List<Span> list = new ArrayList<>(spans);
            Collections.reverse(list);
            return Collections.unmodifiableList(list);
        }

        final List<Span> list = new ArrayList<>(0);

        final Iterator<Span> iterator = spans.descendingIterator();
        Span span;

        while (iterator.hasNext()) {
            span = iterator.next();
            
            
            
            if (
                    (span.start >= start && span.start < end)
                            || (span.end <= end && span.end > start)
                            || (span.start < start && span.end > end)) {
                list.add(span);
            }
        }

        return Collections.unmodifiableList(list);
    }
@ NonNull public List < Span > getSpans ( int start , int end ) { final int length = length ( ) ; if ( ! isPositionValid ( length , start , end ) ) { // we might as well throw here return Collections . emptyList ( ) ; } // all requested if ( start == 0 && length == end ) { // but also copy (do not allow external modification) final List < Span > list = new ArrayList <> ( spans ) ; Collections . reverse ( list ) ; return Collections . unmodifiableList ( list ) ; } final List < Span > list = new ArrayList <> ( 0 ) ; final Iterator < Span > iterator = spans . descendingIterator ( ) ; Span span ; while ( iterator . hasNext ( ) ) { span = iterator . next ( ) ; // we must execute 2 checks: if overlap with specified range or fully include it // if span.start is >= range.start -> check if it's before range.end // if span.end is <= end -> check if it's after range.start if ( ( span . start >= start && span . start < end ) || ( span . end <= end && span . end > start ) || ( span . start < start && span . end > end ) ) { list . add ( span ) ; } } return Collections . unmodifiableList ( list ) ; }
This method will return all {@link Span} spans that <em>overlap</em> specified range,
so if for example a 1..9 range is specified some spans might have 0..6 or 0..10 start/end ranges.
<<<<<<< HEAD:markwon-core/src/main/java/ru/noties/markwon/SpannableBuilder.java
NB spans are returned in reversed order (not in order that we store them internally)
=======
NB spans are returned in reversed order (no in order that we store them internally)
>>>>>>> master:markwon/src/main/java/ru/noties/markwon/SpannableBuilder.java

@since 2.0.1
This method will return all { @link Span } spans that <em > overlap< / em > specified range so if for example a 1 .. 9 range is specified some spans might have 0 .. 6 or 0 .. 10 start / end ranges . <<<<<<< HEAD : markwon - core / src / main / java / ru / noties / markwon / SpannableBuilder . java NB spans are returned in reversed order ( not in order that we store them internally ) ======= NB spans are returned in reversed order ( no in order that we store them internally ) >>>>>>> master : markwon / src / main / java / ru / noties / markwon / SpannableBuilder . java