public static void repl( StringBuffer str, String code, String repl ) {
    if ( ( code == null ) || ( repl == null ) || ( code.length() == 0 ) || ( repl.length() == 0 ) || ( str == null ) || ( str.length() == 0 ) ) {
      return; // do nothing
    }
    String aString = str.toString();
    str.setLength( 0 );
    str.append( aString.replaceAll( Pattern.quote( code ), Matcher.quoteReplacement( repl ) ) );
  }
@Test
  public void testRepl() {
    String source = "A journey of a thousand miles never begins";
    StringBuffer sb = new StringBuffer( source );
    Const.repl( sb, "never begins", "begins with a single step" );
    assertEquals( "A journey of a thousand miles begins with a single step", sb.toString() );
    sb = new StringBuffer( source );
    Const.repl( sb, "evil", "good" );
    assertEquals( source, sb.toString() );
    sb = new StringBuffer( "short" );
    Const.repl( sb, "long pattern", "replacement" );
    assertEquals( "short", sb.toString() );
    sb = new StringBuffer( "" );
    Const.repl( sb, "anything", "something" );
    assertEquals( "", sb.toString() );
    sb = new StringBuffer( "Replace what looks like a regex '[a-z1-3*+]' with '$1'" );
    Const.repl( sb, "[a-z1-3*+]", "$1" );
    assertEquals( "Replace what looks like a regex '$1' with '$1'", sb.toString() );

    // StringBuilder version
    StringBuilder sb2 = new StringBuilder( source );
    Const.repl( sb2, "never begins", "begins with a single step" );
    assertEquals( "A journey of a thousand miles begins with a single step", sb2.toString() );
    sb2 = new StringBuilder( source );
    Const.repl( sb2, "evil", "good" );
    assertEquals( source, sb2.toString() );
    sb2 = new StringBuilder( "short" );
    Const.repl( sb2, "long pattern", "replacement" );
    assertEquals( "short", sb2.toString() );
    sb2 = new StringBuilder( "" );
    Const.repl( sb2, "anything", "something" );
    assertEquals( "", sb2.toString() );
    sb2 = new StringBuilder( "Replace what looks like a regex '[a-z1-3*+]' with '$1'" );
    Const.repl( sb2, "[a-z1-3*+]", "$1" );
    assertEquals( "Replace what looks like a regex '$1' with '$1'", sb2.toString() );

    sb2 = new StringBuilder( "JUNK" );
    Const.repl(  sb2, null, "wibble" );
    assertEquals( "JUNK", sb2.toString() );
    Const.repl(  sb2, "JUNK", null );

  }