Package com.helger.commons.text.util
Class TextVariableHelper
java.lang.Object
com.helger.commons.text.util.TextVariableHelper
This class provides an easy way to replace variables in a string with other
values. The variables need to be present in the form of
${bla}.
The variable helper supports masking with the backslash (\)
character so that the "$" can be represented as "\$".- Since:
- 10.2.0
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsVariables(String sSourceString) Quickly check if a string contains a variable.static voidforEachTextAndVariable(String sSourceString, Consumer<String> aTextFragmentHandler, Consumer<String> aVariableNameHandler) Parse the provided source string looking for variables in the form${...}and invoke callbacks for either text fragments or variable names.static StringgetWithReplacedVariables(String sSourceString, UnaryOperator<String> aVariableProvider)
-
Method Details
-
containsVariables
Quickly check if a string contains a variable.- Parameters:
sSourceString- the string to check for variables.- Returns:
trueif at least one variable is contained,falseif not.
-
forEachTextAndVariable
public static void forEachTextAndVariable(@Nullable String sSourceString, @Nonnull Consumer<String> aTextFragmentHandler, @Nonnull Consumer<String> aVariableNameHandler) Parse the provided source string looking for variables in the form${...}and invoke callbacks for either text fragments or variable names.- Parameters:
sSourceString- The source string to parse and analyze. May benull.aTextFragmentHandler- The callback to be invoked for each text fragment. May not benull.aVariableNameHandler- The callback to be invoked for each variable name. May not benull.
-
getWithReplacedVariables
-