Class ReplaceFunction
- java.lang.Object
-
- com.api.jsonata4java.expressions.functions.FunctionBase
-
- com.api.jsonata4java.expressions.functions.ReplaceFunction
-
public class ReplaceFunction extends FunctionBase
From http://docs.jsonata.org/string-functions.html: $replace(str, pattern, replacement [, limit]) Finds occurrences of pattern within str and replaces them with replacement. If str is not specified, then the context value is used as the value of str. It is an error if str is not a string. The pattern parameter can either be a string or a regular expression (regex). If it is a string, it specifies the substring(s) within str which should be replaced. If it is a regex, its is used to find. The replacement parameter can either be a string or a function. If it is a string, it specifies the sequence of characters that replace the substring(s) that are matched by pattern. If pattern is a regex, then the replacement string can refer to the characters that were matched by the regex as well as any of the captured groups using a S followed by a number N: * If N = 0, then it is replaced by substring matched by the regex as a whole. * If N > 0, then it is replaced by the substring captured by the Nth parenthesised group in the regex. * If N is greater than the number of captured groups, then it is replaced by the empty string. * A literal $ character must be written as $$ in the replacement string If the replacement parameter is a function, then it is invoked for each match occurrence of the pattern regex. The replacement function must take a single parameter which will be the object structure of a regex match as described in the $match function; and must return a string. The optional limit parameter, is a number that specifies the maximum number of replacements to make before stopping. The remainder of the input beyond this limit will be copied to the output unchanged. Examples $replace("John Smith and John Jones", "John", "Mr")=="Mr Smith and Mr Jones" $replace("John Smith and John Jones", "John", "Mr", 1)=="Mr Smith and John Jones" $replace("abracadabra", "a.*?a", "*")=="*c*bra" $replace("John Smith", "(\w+)\s(\w+)", "$2, $1")=="Smith, John" $replace("265USD", "([0-9]+)USD", "$$$1")=="$265"
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.api.jsonata4java.expressions.functions.FunctionBase
FunctionBase.CtxEvalResult
-
-
Field Summary
Fields Modifier and Type Field Description static StringERR_ARG1BADTYPEstatic StringERR_ARG2BADTYPEstatic StringERR_ARG3BADTYPEstatic StringERR_ARG4BADTYPEstatic StringERR_ARG5BADTYPEstatic StringERR_BAD_CONTEXTstatic StringERR_MSG_ARG2_EMPTY_STR
-
Constructor Summary
Constructors Constructor Description ReplaceFunction()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxArgs()intgetMinArgs()StringgetSignature()com.fasterxml.jackson.databind.JsonNodeinvoke(ExpressionsVisitor expressionVisitor, MappingExpressionParser.Function_callContext ctx)static Stringjsonata2JavaReplacement(String in)-
Methods inherited from class com.api.jsonata4java.expressions.functions.FunctionBase
evalContext, getArgumentCount, getFunctionName
-
-
-
-
Field Detail
-
ERR_BAD_CONTEXT
public static String ERR_BAD_CONTEXT
-
ERR_ARG1BADTYPE
public static String ERR_ARG1BADTYPE
-
ERR_ARG2BADTYPE
public static String ERR_ARG2BADTYPE
-
ERR_ARG3BADTYPE
public static String ERR_ARG3BADTYPE
-
ERR_ARG4BADTYPE
public static String ERR_ARG4BADTYPE
-
ERR_ARG5BADTYPE
public static String ERR_ARG5BADTYPE
-
ERR_MSG_ARG2_EMPTY_STR
public static final String ERR_MSG_ARG2_EMPTY_STR
-
-
Method Detail
-
invoke
public com.fasterxml.jackson.databind.JsonNode invoke(ExpressionsVisitor expressionVisitor, MappingExpressionParser.Function_callContext ctx)
- Specified by:
invokein classFunctionBase
-
getMaxArgs
public int getMaxArgs()
- Specified by:
getMaxArgsin classFunctionBase
-
getMinArgs
public int getMinArgs()
- Specified by:
getMinArgsin classFunctionBase
-
getSignature
public String getSignature()
- Specified by:
getSignaturein classFunctionBase
-
-