Class WordReplacer
- java.lang.Object
-
- com.cloudbees.jenkins.support.util.WordReplacer
-
public class WordReplacer extends Object
-
-
Constructor Summary
Constructors Constructor Description WordReplacer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
replaceWord(StringBuilder input, String word, String replace)
Replace all occurrences of word by replace in the input.static String
replaceWord(String input, String word, String replace)
Replace all occurrences of word by replace in the input.static void
replaceWordIgnoreCase(StringBuilder input, String word, String replace)
static String
replaceWordIgnoreCase(String input, String word, String replace)
Replace all occurrences of word by replace in the input.static void
replaceWords(StringBuilder input, String[] words, String[] replaces)
static String
replaceWords(String input, String[] words, String[] replaces)
Replace all words in the input by the replaces.static String
replaceWords(String input, Pattern pattern, Function<String,String> replace)
Replace all matches in the input by their replacement.static String
replaceWords(String input, Pattern pattern, Map<String,String> replacements)
Replace all matches in the input by their replacement.static void
replaceWordsIgnoreCase(StringBuilder input, String[] words, String[] replaces)
static String
replaceWordsIgnoreCase(String input, String[] words, String[] replaces)
Replace all words in the input by the replaces.
-
-
-
Method Detail
-
replaceWords
public static String replaceWords(String input, Pattern pattern, Map<String,String> replacements)
Replace all matches in the input by their replacement. Matcher#appendReplacement is used and therefore `\` and `$` characters must be escaped in the replacement string. NOTE: To ignore casing, Pattern must be case-insensitive or contain all possible cases. And replacements must either be a case-insensitive map or have lowercase keys.- Parameters:
input
- the text where the replacements take placepattern
- the patternreplacements
- the new words to use
-
replaceWords
public static String replaceWords(String input, Pattern pattern, Function<String,String> replace)
Replace all matches in the input by their replacement. Matcher#appendReplacement is used and therefore `\` and `$` characters must be escaped in the replacement string. NOTE: To ignore casing, Pattern must be case-insensitive or contain all possible cases.- Parameters:
input
- the text where the replacements take placepattern
- the patternreplace
- the replace function. Accepts the matched word, and return the replacement
-
replaceWords
public static String replaceWords(String input, String[] words, String[] replaces)
Replace all words in the input by the replaces. The replacements happens only if the texts to replace are not part of a greater word, that is, if the text is a whole word, separated by nonCharacter.isLetterOrDigit(char)
characters.- Parameters:
input
- the text where the replacements take placewords
- the words to look for and replacereplaces
- the new words to use
-
replaceWordsIgnoreCase
public static String replaceWordsIgnoreCase(String input, String[] words, String[] replaces)
Replace all words in the input by the replaces. The replacements happens only if the texts to replace are not part of a greater word, that is, if the text is a whole word, separated by nonCharacter.isLetterOrDigit(char)
characters.- Parameters:
input
- the text where the replacements take placewords
- the words to look for and replacereplaces
- the new words to use
-
replaceWords
public static void replaceWords(StringBuilder input, String[] words, String[] replaces)
- Parameters:
input
- the text where the replacements take placewords
- the words to look for and replacereplaces
- the new words to use
-
replaceWordsIgnoreCase
public static void replaceWordsIgnoreCase(StringBuilder input, String[] words, String[] replaces)
- Parameters:
input
- the text where the replacements take placewords
- the words to look for and replacereplaces
- the new words to use
-
replaceWord
public static String replaceWord(String input, String word, String replace)
Replace all occurrences of word by replace in the input. The replacement happens only if the word to replace is separated from others words, that is, it's not part of a word. The implementation is that the previous and next characters of the word must be aCharacter.isLetterOrDigit(char)
char.- Parameters:
input
- text where the replacements take placeword
- the word to replacereplace
- the new text to use
-
replaceWordIgnoreCase
public static String replaceWordIgnoreCase(String input, String word, String replace)
Replace all occurrences of word by replace in the input. The replacement happens only if the word to replace is separated from others words, that is, it's not part of a word. The implementation is that the previous and next characters of the word must be aCharacter.isLetterOrDigit(char)
char.- Parameters:
input
- text where the replacements take placeword
- the word to replacereplace
- the new text to use
-
replaceWord
public static void replaceWord(StringBuilder input, String word, String replace)
Replace all occurrences of word by replace in the input. The replacement happens only if the word to replace is separated from others words, that is, it's not part of a word. The implementation is that the previous and next characters of the word must be aCharacter.isLetterOrDigit(char)
char.- Parameters:
input
- text where the replacements take placeword
- the word to replacereplace
- the new text to use
-
replaceWordIgnoreCase
public static void replaceWordIgnoreCase(StringBuilder input, String word, String replace)
-
-