static void adjustIndicesForEscapedChars(List<? extends FormattedUrlEntity> entities,List<int[]> indices){
  if (entities == null || indices == null || indices.isEmpty()) {
    return;
  }
  final int size=indices.size();
  int m=0;
  int diff=0;
  int inDiff;
  int len;
  int start;
  int end;
  int i;
  int[] index;
  for (  FormattedUrlEntity entity : entities) {
    inDiff=0;
    for (i=m; i < size; i++) {
      index=indices.get(i);
      start=index[0];
      end=index[1];
      len=end - start;
      if (end < entity.start) {
        diff+=len;
        m++;
      }
 else       if (end < entity.end) {
        inDiff+=len;
      }
    }
    entity.start=entity.start - diff;
    entity.end=entity.end - (diff + inDiff);
  }
}

static void adjustIndicesForEscapedChars ( List < ? extends FormattedUrlEntity > entities , List < int [ ] > indices ) { if ( entities == null || indices == null || indices . isEmpty ( ) ) { return ; } final int size = indices . size ( ) ; int m = 0 ; int diff = 0 ; int inDiff ; int len ; int start ; int end ; int i ; int [ ] index ; for ( FormattedUrlEntity entity : entities ) { inDiff = 0 ; for ( i = m ; i < size ; i ++ ) { index = indices . get ( i ) ; start = index [ 0 ] ; end = index [ 1 ] ; len = end - start ; if ( end < entity . start ) { diff += len ; m ++ ; } else if ( end < entity . end ) { inDiff += len ; } } entity . start = entity . start - diff ; entity . end = entity . end - ( diff + inDiff ) ; } }
since the unescaping of html causes for example & amp ; to turn into & we need to adjust the entity indices after that by 4 characters . this loops through the entities and adjusts them as necessary .
