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 (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 πŸ’–βœ¨πŸŽ€πŸ¦‹