public LinkedList<Diff> diff_fromDelta(String text1,String delta) throws IllegalArgumentException {
  LinkedList<Diff> diffs=new LinkedList<Diff>();
  int pointer=0;
  String[] tokens=delta.split("\t");
  for (  String token : tokens) {
    if (token.length() == 0) {
      continue;
    }
    String param=token.substring(1);
switch (token.charAt(0)) {
case '+':
      param=param.replace("+","%2B");
    try {
      param=URLDecoder.decode(param,"UTF-8");
    }
 catch (    UnsupportedEncodingException e) {
      throw new Error("This system does not support UTF-8.",e);
    }
catch (    IllegalArgumentException e) {
      throw new IllegalArgumentException("Illegal escape in diff_fromDelta: " + param,e);
    }
  diffs.add(new Diff(Operation.INSERT,param));
break;
case '-':
case '=':
int n;
try {
n=Integer.parseInt(param);
}
 catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid number in diff_fromDelta: " + param,e);
}
if (n < 0) {
throw new IllegalArgumentException("Negative number in diff_fromDelta: " + param);
}
String text;
try {
text=text1.substring(pointer,pointer+=n);
}
 catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Delta length (" + pointer + ") larger than source text length ("+ text1.length()+ ").",e);
}
if (token.charAt(0) == '=') {
diffs.add(new Diff(Operation.EQUAL,text));
}
 else {
diffs.add(new Diff(Operation.DELETE,text));
}
break;
default :
throw new IllegalArgumentException("Invalid diff operation in diff_fromDelta: " + token.charAt(0));
}
}
if (pointer != text1.length()) {
throw new IllegalArgumentException("Delta length (" + pointer + ") smaller than source text length ("+ text1.length()+ ").");
}
return diffs;
}

public LinkedList < Diff > diff_fromDelta ( String text1 , String delta ) throws IllegalArgumentException { LinkedList < Diff > diffs = new LinkedList < Diff > ( ) ; int pointer = 0 ; String [ ] tokens = delta . split ( "\t" ) ; for ( String token : tokens ) { if ( token . length ( ) == 0 ) { continue ; } String param = token . substring ( 1 ) ; switch ( token . charAt ( 0 ) ) { case '+' : param = param . replace ( "+" , "%2B" ) ; try { param = URLDecoder . decode ( param , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { throw new Error ( "This system does not support UTF-8." , e ) ; } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException ( "Illegal escape in diff_fromDelta: " + param , e ) ; } diffs . add ( new Diff ( Operation . INSERT , param ) ) ; break ; case '-' : case '=' : int n ; try { n = Integer . parseInt ( param ) ; } catch ( NumberFormatException e ) { throw new IllegalArgumentException ( "Invalid number in diff_fromDelta: " + param , e ) ; } if ( n < 0 ) { throw new IllegalArgumentException ( "Negative number in diff_fromDelta: " + param ) ; } String text ; try { text = text1 . substring ( pointer , pointer += n ) ; } catch ( StringIndexOutOfBoundsException e ) { throw new IllegalArgumentException ( "Delta length (" + pointer + ") larger than source text length (" + text1 . length ( ) + ")." , e ) ; } if ( token . charAt ( 0 ) == '=' ) { diffs . add ( new Diff ( Operation . EQUAL , text ) ) ; } else { diffs . add ( new Diff ( Operation . DELETE , text ) ) ; } break ; default : throw new IllegalArgumentException ( "Invalid diff operation in diff_fromDelta: " + token . charAt ( 0 ) ) ; } } if ( pointer != text1 . length ( ) ) { throw new IllegalArgumentException ( "Delta length (" + pointer + ") smaller than source text length (" + text1 . length ( ) + ")." ) ; } return diffs ; }
given the original text1 , and an encoded string which describes the operations required to transform text1 into text2 , compute the full diff .
