Add a replacement for the special character c which may be a string

@param c the character to replace
@param replacement the new string
324296
protected void addSpecial(String c, String replacement) {
    specialString += c;
    special.put(c, replacement);
  }
351084
public static String replaceAnyOf(String value, String chars,
                                    char replacement) {
    char[] tmp = new char[value.length()];
    int pos = 0;
    for (int ix = 0; ix < tmp.length; ix++) {
      char ch = value.charAt(ix);
      if (chars.indexOf(ch) != -1)
        tmp[pos++] = replacement;
      else
        tmp[pos++] = ch;
    }
    return new String(tmp, 0, tmp.length);
  }
806085
public static String replace(final String string, final String find, final String replacement) {
		int pos = string.indexOf(find);
		//System.out.println(string+": "+find+" at "+pos);
		if (pos == -1) return string;
		StringBuilder SB = new StringBuilder();
		int lastpos = 0;
		final int findLen = find.length();
		do {
			SB.append(string, lastpos, pos).append(replacement);
			lastpos = pos + findLen;
			pos = string.indexOf(find, lastpos);
		} while (pos != -1);
		int len = string.length();
		if(lastpos<len) SB.append(string, lastpos, len);
		return SB.toString();
	}
900377
public static void replaceBadXmlCharactersBySpace(char[] cbuf, int off, int len) {
        for (int i = off; i < off + len; i++) {
            if (isBadXmlCharacter(cbuf[i])) {
                cbuf[i] = '\u0020';
            }
        }
    }
1139805
public void addMeta(char meta, String replacement) {
        metaCharacterSet.set(meta);
        replacementMap.put(new String(new char[] { meta }), replacement);
    }
468629
public Expression2 substitute(String value, String replacement) {
    return substitute(Expression2.constant(value), Expression2.constant(replacement));
  }
970588
public void register(final String word, final String replacement) {
        ArgUtils.notEmpty(word, "word");
        ArgUtils.notNull(replacement, "replacement");
        
        if(word.length() == 1) {
            singles.computeIfAbsent(word.charAt(0), key -> replacement);
            
        } else {
            multi.add(new MultiChar(word, replacement));
        }
        
    }
412369
public static String replace(String s, String target, String replacement)
  {
    // String.replace() is suboptimal in JDK8, but is fixed in JDK9+. When the minimal JDK version supported by Druid is
    // JDK9+, the implementation of this method should be replaced with simple delegation to String.replace(). However,
    // the method should still be prohibited to use in all other places except this method body, because it's easy to
    // suboptimally call String.replace("a", "b"), String.replace("a", ""), String.replace("a", "abc"), which have
    // better alternatives String.replace('a', 'b'), removeChar() and replaceChar() respectively.
    int pos = s.indexOf(target);
    if (pos < 0) {
      return s;
    }
    int sLength = s.length();
    int targetLength = target.length();
    // This is needed to work correctly with empty target string and mimic String.replace() behavior
    int searchSkip = Math.max(targetLength, 1);
    StringBuilder sb = new StringBuilder(sLength - targetLength + replacement.length());
    int prevPos = 0;
    do {
      sb.append(s, prevPos, pos);
      sb.append(replacement);
      prevPos = pos + targetLength;
      // Break from the loop if the target is empty
      if (pos == sLength) {
        break;
      }
      pos = s.indexOf(target, pos + searchSkip);
    } while (pos > 0);
    sb.append(s, prevPos, sLength);
    return sb.toString();
  }
478869
public static String regexpReplace(String str, String regex, String replacement) {
		if (regex.isEmpty()) {
			return str;
		}
		try {
			// we should use StringBuffer here because Matcher only accept it
			StringBuffer sb = new StringBuffer();
			Matcher m = REGEXP_PATTERN_CACHE.get(regex).matcher(str);
			while (m.find()) {
				m.appendReplacement(sb, replacement);
			}
			m.appendTail(sb);
			return sb.toString();
		} catch (Exception e) {
			LOG.error(
				String.format("Exception in regexpReplace('%s', '%s', '%s')", str, regex, replacement),
				e);
			// return null if exception in regex replace
			return null;
		}
	}
859344
private void replaceCommandLine(String replacement) {
		int currentCLSize = commandLineBuffer.size();
		commandLineBuffer = new ByteArrayOutputStream();
		for (int x = 0; x < replacement.length(); x++) {
			commandLineBuffer.write(replacement.charAt(x));
		}
		String replaceString = '\r' + promptStr;
		for (int x = 0; x <= currentCLSize; x++) {
			replaceString += ' ';
		}
		replaceString += '\r' + promptStr + replacement;
		ps.print(replaceString);
	}
169399
private void append(StringBuilder buffer, char c) {

		// version manually simplified
		// final boolean shouldAppend = rawOutput || escaped
		// || (c != quoteChar && c != escapeChar);
		// final boolean newEscaped = c == escapeChar && !escaped;
		// final boolean newQuoted = (c == quoteChar && !escaped) ? !quoted
		// : quoted;

		// side-effect free version directly extracted from if

		// final boolean shouldAppend = (c == escapeChar && (escaped ||
		// rawOutput))
		// || (c == quoteChar && (escaped || rawOutput))
		// || !(c == quoteChar || c == escapeChar);
		// final boolean newEscaped = c == escapeChar ? !escaped
		// : (c == quoteChar ? false : false);
		// final boolean newQuoted = c == escapeChar ? quoted
		// : (c == quoteChar ? (!escaped ? !quoted : quoted) : quoted);

		// if (shouldAppend) {
		// buffer.append(c);
		// }
		//
		// escaped = newEscaped;
		// quoted = newQuoted;

		// original version
		// XXX needed to revert to this original version as micro benchmark
		// tests
		// showed a slow down of more than 100%
		if (c == escapeChar) {
			if (escaped || rawOutput) {
				buffer.append(c);
			}
			escaped = !escaped;
		} else if (c == quoteChar) {
			if (escaped) {
				buffer.append(c);
				escaped = false;
			} else {
				quoted = !quoted;
				if (rawOutput) {
					buffer.append(c);
				}
			}
		} else {
			buffer.append(c);
			escaped = false;
		}
	}
653168
static String fastReplace( String str, String target, String replacement ) {
        int targetLength = target.length();
        if( targetLength == 0 ) {
            return str;
        }
        int idx2 = str.indexOf( target );
        if( idx2 < 0 ) {
            return str;
        }
        StringBuilder buffer = new StringBuilder( targetLength > replacement.length() ? str.length() : str.length() * 2 );
        int idx1 = 0;
        do {
            buffer.append( str, idx1, idx2 );
            buffer.append( replacement );
            idx1 = idx2 + targetLength;
            idx2 = str.indexOf( target, idx1 );
        } while( idx2 > 0 );
        buffer.append( str, idx1, str.length() );
        return buffer.toString();
    }
1139453
public static void setChar (@Nonnull final CharSequence aSeq, final int nIndex, final int nCodepoint)
  {
    if (!(aSeq instanceof StringBuilder) && !(aSeq instanceof StringBuffer))
    {
      setChar (new StringBuilder (aSeq), nIndex, nCodepoint);
    }
    else
    {
      int l = 1;
      int nI = nIndex;
      final char ch = aSeq.charAt (nI);
      final boolean high = Character.isHighSurrogate (ch);
      final boolean low = Character.isLowSurrogate (ch);
      if (high || low)
      {
        if (high && (nI + 1) < aSeq.length () && Character.isLowSurrogate (aSeq.charAt (nI + 1)))
          l++;
        else
        {
          if (low && nI > 0 && Character.isHighSurrogate (aSeq.charAt (nI - 1)))
          {
            nI--;
            l++;
          }
        }
      }
      if (aSeq instanceof StringBuffer)
        ((StringBuffer) aSeq).replace (nI, nI + l, getAsString (nCodepoint));
      else
        ((StringBuilder) aSeq).replace (nI, nI + l, getAsString (nCodepoint));
    }
  }
813724
public void addString(String str)
    {
        if (sourceNode != null)
        {
            addStringInternal(str);
            replaceOrRegister(sourceNode, str);
        }
        else
        {
            unSimplify();
            addString(str);
        }
    }
1065145
public static String replace(String str, String search, String replace) {
        if (str == null || search == null || replace == null) {
            return str;
        }
        StringBuilder sb = new StringBuilder();
        int searchLen = search.length();
        int stringLen = str.length();
        int oldIndex = 0;
        int index;
        while ((index = str.indexOf(search, oldIndex)) >= 0) {
            sb.append(str, oldIndex, index);
            sb.append(replace);
            oldIndex = index + searchLen;
        }
        if (oldIndex < stringLen) {
            sb.append(str, oldIndex, stringLen);
        }
        return sb.toString();
    }
912939
public final String stringReplace(
        String toBeReplaced,
        String toReplace,
        String replacement
    ) {
        Pattern pattern = Pattern.compile(toReplace);
        Matcher match = pattern.matcher(toBeReplaced);

        while (match.find()) {
            toBeReplaced = match.replaceAll(replacement);
            match = pattern.matcher(toBeReplaced);
        }

        return toBeReplaced;
    }
71733
public static String replaceLast(String source, char toReplace, char with) {
    StringBuilder sb = new StringBuilder(source);
    int index = sb.lastIndexOf(String.valueOf(toReplace));
    if (index != -1) {
      sb.setCharAt(index, with);
    }
    return sb.toString();
  }