private static void do_replace(GlobData rdata,Context cx,RegExpImpl regExpImpl){
  StringBuilder charBuf=rdata.charBuf;
  int cp=0;
  String da=rdata.repstr;
  int dp=rdata.dollar;
  if (dp != -1) {
    int[] skip=new int[1];
    do {
      int len=dp - cp;
      charBuf.append(da.substring(cp,dp));
      cp=dp;
      SubString sub=interpretDollar(cx,regExpImpl,da,dp,skip);
      if (sub != null) {
        len=sub.length;
        if (len > 0) {
          charBuf.append(sub.str,sub.index,sub.index + len);
        }
        cp+=skip[0];
        dp+=skip[0];
      }
 else {
        ++dp;
      }
      dp=da.indexOf('$',dp);
    }
 while (dp >= 0);
  }
  int daL=da.length();
  if (daL > cp) {
    charBuf.append(da.substring(cp,daL));
  }
}

private static void do_replace ( GlobData rdata , Context cx , RegExpImpl regExpImpl ) { StringBuilder charBuf = rdata . charBuf ; int cp = 0 ; String da = rdata . repstr ; int dp = rdata . dollar ; if ( dp != - 1 ) { int [ ] skip = new int [ 1 ] ; do { int len = dp - cp ; charBuf . append ( da . substring ( cp , dp ) ) ; cp = dp ; SubString sub = interpretDollar ( cx , regExpImpl , da , dp , skip ) ; if ( sub != null ) { len = sub . length ; if ( len > 0 ) { charBuf . append ( sub . str , sub . index , sub . index + len ) ; } cp += skip [ 0 ] ; dp += skip [ 0 ] ; } else { ++ dp ; } dp = da . indexOf ( '$' , dp ) ; } while ( dp >= 0 ) ; } int daL = da . length ( ) ; if ( daL > cp ) { charBuf . append ( da . substring ( cp , daL ) ) ; } }
analog of do_replace in jsstr . c
