code: public static void copySpansFrom(Spanned source, int start, int end,
                                       Class kind,
                                       Spannable dest, int destoff) {
          if (kind == null) {
              kind = Object.class;
          }
  
          Object[] spans = source.getSpans(start, end, kind);
  
          for (int i = 0; i < spans.length; i++) {
              int st = source.getSpanStart(spans[i]);
              int en = source.getSpanEnd(spans[i]);
              int fl = source.getSpanFlags(spans[i]);
  
              if (st < start)
                  st = start;
              if (en > end)
                  en = end;
  
              dest.setSpan(spans[i], st - start + destoff, en - start + destoff,
                           fl);
          }
      }
docs: Copies the spans from the region <code>start...end</code> in
  <code>source</code> to the region
  <code>destoff...destoff+end-start</code> in <code>dest</code>.
  Spans in <code>source</code> that begin before <code>start</code>
  or end after <code>end</code> but overlap this range are trimmed
  as if they began at <code>start</code> or ended at <code>end</code>.
  
  @throws IndexOutOfBoundsException if any of the copied spans
  are out of range in <code>dest</code>.