Package com.helger.commons.text.util
Class TextVariableHelper
- java.lang.Object
-
- com.helger.commons.text.util.TextVariableHelper
-
@Immutable public final class TextVariableHelper extends Object
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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 Detail
-
containsVariables
public static boolean containsVariables(@Nullable String sSourceString)
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.
-
-