Class Envsubst


  • public class Envsubst
    extends Object
    A basic 'envsubst' implementation. Just uses regex matching for substituting placeholders in a string. Does not precompile templates - we may want to switch to a fully fledged template engine for that.
    • Field Detail

      • PLACEHOLDER_PATTERN

        public static final Pattern PLACEHOLDER_PATTERN
        Regex for matching strings such as '${varname}' variable names cannot include the '}' symbol
    • Constructor Detail

      • Envsubst

        public Envsubst()
    • Method Detail

      • envsubst

        public static String envsubst​(String input,
                                      java.util.function.Function<String,​String> getReplacement)
        Perform substitution of placeholders of form "${name}"
        Parameters:
        input - A string in which to replace placeholder patterns
        getReplacement - Function that receives the variable name of a match and can return a substitution string. A result of null leaves the placeholder unchanged in order to allow for future substitution.
        Returns: