Converts plan text into anonymous text. Preserves upper case, lower case,
punctuation, whitespace and digits while making the text unreadable.

@param oldText text to replace
@param replacements map of find/replace pairs
550181
private void mapText(String oldText, Map<String, String> replacements)
   {
      char c2 = 0;
      if (oldText != null && oldText.length() != 0 && !replacements.containsKey(oldText))
      {
         StringBuilder newText = new StringBuilder(oldText.length());
         for (int loop = 0; loop < oldText.length(); loop++)
         {
            char c = oldText.charAt(loop);
            if (Character.isUpperCase(c))
            {
               newText.append('X');
            }
            else
            {
               if (Character.isLowerCase(c))
               {
                  newText.append('x');
               }
               else
               {
                  if (Character.isDigit(c))
                  {
                     newText.append('0');
                  }
                  else
                  {
                     if (Character.isLetter(c))
                     {
                        // Handle other codepages etc. If possible find a way to
                        // maintain the same code page as original.
                        // E.g. replace with a character from the same alphabet.
                        // This 'should' work for most cases
                        if (c2 == 0)
                        {
                           c2 = c;
                        }
                        newText.append(c2);
                     }
                     else
                     {
                        newText.append(c);
                     }
                  }
               }
            }
         }

         replacements.put(oldText, newText.toString());
      }
   }
795681
public int replace(String text) {
        int delta=text.length()-(cpLimit-cpStart);
        rep.replace(cpStart, cpLimit, text);
        cpLimit+=delta;
        limit+=delta;
        contextLimit+=delta;
        return delta;
    }
775314
function(key, replacements) {
        var message = messageMap[key];

        if (replacements) {
            message = util.replaceText(message, replacements);
        }

        return message;
    }
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);
	}
875092
def replace(text, separator = LINE_BREAK)
      text.gsub(/([ ]+)#{separator}/, "\\1")
          .gsub(/#{separator}(?<space>[ ]+)/, "\\k<space>")
          .gsub(/#{separator}/, ' ')
    end
226619
public String replace(CharSequence text)
    {
        StringBuilder sb = new StringBuilder();
        replace(sb, text);
        return sb.toString();
    }
916360
public String replace( String input, String replacement ) throws ParameterOutOfBoundsException {
        // Replace \ in the replacement with \\ to escape it for Java replace.
        replacement = REPLACEMENT_BACKSLASH.matcher( replacement ).replaceAll( REPLACEMENT_BACKSLASH_FOR_JAVA );

        // Replace the Javascript-ese $& in the replacement with Java-ese $0, but
        // watch out for $$&, which should stay $$&, to be changed to \$& below.
        replacement = REPLACEMENT_DOLLAR_AMPERSAND.matcher( replacement ).replaceAll( REPLACEMENT_DOLLAR_AMPERSAND_FOR_JAVA );

        // Test for Javascript-ese $` and $', which we do not support in the pure
        // Java version.
        if( REPLACEMENT_DOLLAR_APOSTROPHE.matcher( replacement ).find() ) {
            throw new ParameterOutOfBoundsException();
        }

        // Replace the Javascript-ese $$ in the replacement with Java-ese \$.
        replacement = REPLACEMENT_DOLLAR_DOLLAR.matcher( replacement ).replaceAll( REPLACEMENT_DOLLAR_DOLLAR_FOR_JAVA );

        Matcher matcher = pattern.matcher( input );
        return global ? matcher.replaceAll( replacement ) : matcher.replaceFirst( replacement );
    }
1132356
@Override
	public UserProfile convert(String text)
	{
		if(text == null || text.trim().length() == 0)
			return null;
		
		String[] lines = text.split("\\\n");
		
		BiConsumer<String,UserProfile> strategy = null;
		UserProfile userProfile = null;
		String lineUpper = null;
		for (String line : lines)
		{
			//get first term
			int index = line.indexOf(";");
			if(index < 0)
				continue; //skip line
			//
			String term = line.substring(0, index);
			
			strategy = strategies.get(term.toLowerCase());
			lineUpper = line.toUpperCase();
			if(strategy == null)
			{
				//check for a different format
				//N:Green;Gregory;;;
				if(lineUpper.startsWith("N:"))
					strategy = strategies.get("n");
				else if(lineUpper.startsWith("FN:"))
					strategy = strategies.get("fn");
				else if(lineUpper.contains("EMAIL;"))
					strategy = strategies.get("email");
				else
					continue; //skip
			}
			
			if(userProfile == null)
			{
				userProfile = ClassPath.newInstance(this.userProfileClass);
			}
			
			strategy.accept(line, userProfile);
			
		}
		return userProfile;
	}
1258351
public String replace(CharSequence text, ObsoleteReplacer replacer) throws IOException
    {
        if (text.length() == 0)
        {
            return "";
        }
        CharArrayWriter caw = new CharArrayWriter();
        InputReader reader = Input.getInstance(text);
        replace(reader, caw, replacer);
        return caw.toString();
    }
193559
private static String changeIDs(String text, Map<String, String> mapIds) {
    String result = text;
    for (String key : mapIds.keySet()) {
      result = result.replace(key, mapIds.get(key));
    }
    return result;
  }
36760
public Tuple3<ReadOnlyStyledDocument<PS, SEG, S>, RichTextChange<PS, SEG, S>, MaterializedListModification<Paragraph<PS, SEG, S>>> replace(
            Replacement<PS, SEG, S> replacement) {
        return replace(replacement.getStart(), replacement.getEnd(), replacement.getDocument());
    }
548142
public String replace(CharSequence text, CharSequence replacement)
    {
        try
        {
            if (text.length() == 0)
            {
                if (acceptEmpty)
                {
                    return "";
                }
            }
            CharArrayWriter caw = new CharArrayWriter();
            InputReader reader = Input.getInstance(text);
            ObsoleteSimpleReplacer fsp = new ObsoleteSimpleReplacer(replacement);
            replace(reader, caw, fsp);
            return caw.toString();
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("can't happen", ex);
        }
    }
1142852
public void setAsText(String text) throws IllegalArgumentException {
		if (text == null) {
			setValue(null);
		}
		else {
			setValue(new DistinguishedName(text).immutableDistinguishedName());
		}
	}
31296
public void replace (String... replace)
    {
        HashSet<String> toAdd = Sets.newHashSet();
        Iterator<String> i = _imports.iterator();
        while (i.hasNext()) {
            String name = i.next();
            for (int j = 0; j < replace.length; j += 2) {
                if (name.equals(replace[j])) {
                    toAdd.add(replace[j + 1]);
                    i.remove();
                    break;
                }
            }
        }
        _imports.addAll(toAdd);
    }
196769
def replace(self, text, pattern=None):
        """"""
        cursor = self.textCursor()
        cursor.beginEditBlock()
        if pattern is not None:
            seltxt = to_text_string(cursor.selectedText())
        cursor.removeSelectedText()
        if pattern is not None:
            text = re.sub(to_text_string(pattern),
                          to_text_string(text), to_text_string(seltxt))
        cursor.insertText(text)
        cursor.endEditBlock()
850037
function applyReplacements(str, replacements) {
    var result = "",
        replacement,
        i;

    for (i = 0; i < replacements.length; i++) {
        replacement = replacements[i];
        if (replacement) {
            result += replacement.newStr;
            i += replacement.oldStr.length - 1;
        } else {
            result += str.charAt(i);
        }
    }

    result += str.substr(i, str.length);

    return result;
}
558722
protected function replace($text, $replacements)
    {
        if (is_array($replacements)) {
            foreach ($replacements as $var => $replacement) {
                $regex = str_replace('key', preg_quote($var, '/'), $this->translateReplaceRegex);
                $text = preg_replace($regex, $replacement, $text);
            }
        }
        return $text;
    }