protected String processSubstitution(String substitutionRule,String description,int startPos){
  String replace;
  String replaceWith;
  int equalPos=substitutionRule.indexOf('=');
  replace=substitutionRule.substring(0,equalPos);
  replaceWith=substitutionRule.substring(equalPos + 1);
  handleSpecialSubstitution(replace,replaceWith,startPos,description);
  if (replaceWith.length() == 0) {
    error("Nothing on right-hand side of =",startPos,description);
  }
  if (replace.length() == 0) {
    error("Nothing on left-hand side of =",startPos,description);
  }
  if (replace.length() == 2 && replace.charAt(0) != '\\') {
    error("Illegal left-hand side for =",startPos,description);
  }
  if (replace.length() >= 3 && replace.charAt(0) != '<' && replace.codePointBefore(equalPos) != '>') {
    error("Illegal left-hand side for =",startPos,description);
  }
  if (!(replaceWith.charAt(0) == '[' && replaceWith.charAt(replaceWith.length() - 1) == ']') && !(replaceWith.charAt(0) == '(' && replaceWith.charAt(replaceWith.length() - 1) == ')')) {
    error("Illegal right-hand side for =",startPos,description);
  }
  StringBuffer result=new StringBuffer();
  result.append(description.substring(0,startPos));
  int lastPos=startPos;
  int pos=description.indexOf(replace,startPos);
  while (pos != -1) {
    result.append(description.substring(lastPos,pos));
    result.append(replaceWith);
    lastPos=pos + replace.length();
    pos=description.indexOf(replace,lastPos);
  }
  result.append(description.substring(lastPos));
  return result.toString();
}

protected String processSubstitution ( String substitutionRule , String description , int startPos ) { String replace ; String replaceWith ; int equalPos = substitutionRule . indexOf ( '=' ) ; replace = substitutionRule . substring ( 0 , equalPos ) ; replaceWith = substitutionRule . substring ( equalPos + 1 ) ; handleSpecialSubstitution ( replace , replaceWith , startPos , description ) ; if ( replaceWith . length ( ) == 0 ) { error ( "Nothing on right-hand side of =" , startPos , description ) ; } if ( replace . length ( ) == 0 ) { error ( "Nothing on left-hand side of =" , startPos , description ) ; } if ( replace . length ( ) == 2 && replace . charAt ( 0 ) != '\\' ) { error ( "Illegal left-hand side for =" , startPos , description ) ; } if ( replace . length ( ) >= 3 && replace . charAt ( 0 ) != '<' && replace . codePointBefore ( equalPos ) != '>' ) { error ( "Illegal left-hand side for =" , startPos , description ) ; } if ( ! ( replaceWith . charAt ( 0 ) == '[' && replaceWith . charAt ( replaceWith . length ( ) - 1 ) == ']' ) && ! ( replaceWith . charAt ( 0 ) == '(' && replaceWith . charAt ( replaceWith . length ( ) - 1 ) == ')' ) ) { error ( "Illegal right-hand side for =" , startPos , description ) ; } StringBuffer result = new StringBuffer ( ) ; result . append ( description . substring ( 0 , startPos ) ) ; int lastPos = startPos ; int pos = description . indexOf ( replace , startPos ) ; while ( pos != - 1 ) { result . append ( description . substring ( lastPos , pos ) ) ; result . append ( replaceWith ) ; lastPos = pos + replace . length ( ) ; pos = description . indexOf ( replace , lastPos ) ; } result . append ( description . substring ( lastPos ) ) ; return result . toString ( ) ; }
this function performs variable - name substitutions . first it does syntax checking on the variable - name definition . if it ' s syntactically valid , it then goes through the remainder of the description and does a simple find - and - replace of the variable name with its text . ( the variable text must be enclosed in either [ ] or ( ) for this to work . )
