The string
vmod implements various helper function to manipulate strings.
INT len(STRING S)
Returns the number of ascii characters in S, or -1 if S is null.
Arguments:
S
accepts type STRINGType: Function
Returns: Int
BOOL startswith(STRING S1, STRING S2)
Returns true if S1 starts with S2.
Arguments:
S1
accepts type STRING
S2
accepts type STRING
Type: Function
Returns: Bool
BOOL endswith(STRING S1, STRING S2)
Returns true if S1 ends with S2.
Arguments:
S1
accepts type STRING
S2
accepts type STRING
Type: Function
Returns: Bool
BOOL contains(STRING S1, STRING S2)
Returns true if S1 contains S2.
Arguments:
S1
accepts type STRING
S2
accepts type STRING
Type: Function
Returns: Bool
STRING substr(STRING S, INT N, INT OFFSET = 0)
Returns a substring that is at most abs(N) characters long, from the character at the OFFSET position (negative OFFSET counts from the back of the string). If N is positive, the substring is extracted right of OFFSET, left otherwise.
Example:
If S in NULL, NULL is returned.
Arguments:
S
accepts type STRING
N
accepts type INT
OFFSET
accepts type INT with a default value of 0
optional
Type: Function
Returns: String
STRING reverse(STRING S)
Reverse S.
Arguments:
S
accepts type STRINGType: Function
Returns: String
STRING split(STRING S, INT n, STRING SEP = " \t")
Split s and return the N-th token (index starts at 1). Characters in SEP are separators. A negative N indicate “from the end of the string”. The value of “STRING SEP” can be multiple characters, the vmod will split the string at all of the given values.
Example:
Arguments:
S
accepts type STRING
n
accepts type INT
SEP
accepts type STRING with a default value of \t
optional
Type: Function
Returns: String
BOOL token_intersect(STRING str1, STRING str2, [STRING separators])
Checks if the set tokens in one string intersects the set of tokens in the other string. In other words, it returns true if there is a token which exists in both strings.
If the separators argument is not supplied, the space and comma characters are the separators. Empty tokens are ignored in both strings.
Arguments:
str1
accepts type STRING
str2
accepts type STRING
separators
accepts type STRING
Type: Function
Returns: Bool
The str
VMOD is available in Varnish Enterprise version 6.0.4r3
and later.