Class WordReplacer
java.lang.Object
com.cloudbees.jenkins.support.util.WordReplacer
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
public class WordReplacer
extends Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReplace all matches in the input by their replacement.static StringReplace all matches in the input by their replacement.static StringreplaceWordsByOffset(String input, String normalized, Pattern pattern, Function<String, String> replace) Replace all matches in the normalized text by splicing replacements into the original input at matching offsets.
-
Constructor Details
-
WordReplacer
public WordReplacer()
-
-
Method Details
-
replaceWordsByOffset
public static String replaceWordsByOffset(String input, String normalized, Pattern pattern, Function<String, String> replace) Replace all matches in the normalized text by splicing replacements into the original input at matching offsets. The pattern is matched againstnormalized, but replacements are spliced intoinputusing the same offsets. This is safe when normalization preserves offset alignment (never changescharCount(cp)).Unlike
replaceWords(String, Pattern, Function), this method does not useMatcher#appendReplacement, so\and$in replacements do not need escaping.- Parameters:
input- the original text, returned unchanged if no matchesnormalized- the case-normalized copy ofinput, matched against the patternpattern- the pattern to match (should have no case-insensitive flags sincenormalizedis pre-normalized)replace- function accepting a matched substring fromnormalizedand returning its replacement- Returns:
inputitself when no matches; otherwise a new string with replacements spliced in
-
replaceWords
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
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
-