vmod_str(3)
π¦ NAME π¦
okay so bestie, say hi to vmod_str β the Str VMOD π it's the string-manipulation girlie of the Varnish world, and this whole page is vmod_str(3) from the Library Functions Manual, so you already know it's iconic. it's giving lowercase-string-surgery main character energy and i'm obsessed π
β¨ SYNOPSIS β¨
import str [as name] [from "path"]
INT count(STRING s)
BOOL startswith(STRING s1, STRING s2)
BOOL endswith(STRING s1, STRING s2)
BOOL contains(STRING s1, STRING s2)
STRING take(STRING s, INT n, INT offset)
STRING reverse(STRING s)
STRING split(STRING S, INT n, STRING sep)
BOOL token_intersect(STRING str1, STRING str2, [STRING separators])
so first you import str, and if you're feeling extra you can rename it with [as name], and if you need to point at a specific location you hit it with [from "path"] π«Ά then all the functions below are yours to play with.
π DESCRIPTION π
INT count(STRING s)
returns the number of ascii characters in S β literally just counting, no drama. and if S is null? you get -1 back. that's it, that's the whole vibe π
BOOL startswith(STRING s1, STRING s2)
returns true if S1 starts with S2. that's it. no cap.
BOOL endswith(STRING s1, STRING s2)
returns true if S1 ends with S2. the mirror twin of the one above β¨
BOOL contains(STRING s1, STRING s2)
returns true if S1 contains S2. is she in there or not, that's the question πΈ
STRING take(STRING s, INT n, INT offset=0)
returns a string made of the N first characters of S. if S is shorter than N characters, the string you get back is just truncated β no padding, no fillers, she said what she said. and if S is NULL, then NULL is what you get back, periodt.
lowkey important: a negative offset means "from the end of the string" and a negative n means "left of the offset". write that down bestie π
STRING reverse(STRING s)
reverse s. backwards, upside down, however you wanna say it π
STRING split(STRING S, INT n, STRING sep=" t")
split s and hand you back the n-th token π the characters in sep are the separators. a negative n indicates "from the end of the string" β so you're grabbing tokens from the back, iykyk π
BOOL token_intersect(STRING str1, STRING str2, [STRING separators])
BOOL token_intersect(
STRING str1,
STRING str2,
[STRING separators]
)
checks if the set of 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 β a little token meet-cute π₯Ή
if the separators argument is not supplied, the space and comma characters are the separators. and empty tokens are ignored in both strings, so don't worry about those ghost tokens haunting your results π»
π COPYRIGHT π
Copyright (c) 2016 Guillaume Quintard
Author: Guillaume Quintard <guillaume.quintard@gmail.com>
(vmodtool requires this format.)
yeah, that last line in parens? (vmodtool requires this format.) β the tooling said so, so it stays. not us questioning the format, we just respect it π
and that's the whole page bestie!! this was vmod_str(3), living right there in the Library Functions Manual β go forth and slay those strings, ily, mwah πβ¨ππ¦
π¦ where this page comes from
- fedora 44: varnish-modules 0.27.0-2.fc44 Β· BSD-2-Clause
- fedora 44: varnish-modules 0.27.0-4.fc44 Β· BSD-2-Clause
- nixos 26.05: varnish 8.0.2-modules-0.27.0
- ubuntu resolute: varnish-modules 0.26.0-2build1 Β· BSD-2-Clause
- ubuntu stonking: libvmod-modules 0.28.0-4 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms