ststring(3)

πŸ’– ststring β€” string handling, bestie edition πŸ’–

okay so this is ststring(3) from the ShapeTools Toolkit Library, and it's literally four little string-wrangling functions that are gonna make your life so much easier. no cap. come sit with me. 🫢


✨ NAME ✨

stConvertPattern, stSubstituteString, stStrtok, stStrEnter β€” string handling πŸ’…


🌸 SYNOPSIS 🌸

#include <config.h>
#include <sttk.h>

char* stConvertPattern (char *pattern);

char* stSubstituteString (char *original, char *old, char *new);

char* stStrtok (char *string);

char* stStrEnter (char *string);

like look at those signatures. immaculate. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

stConvertPattern β€” the glow-up function ✨

stConvertPattern takes sh(1) filename generation patterns and converts them into ed(1) string patterns. it's giving translator, it's giving bilingual icon.

here's the tea on what happens to each character:

  • question (?) β€” gets converted to a period (.). simple. slay.
  • asterisk (*) β€” gets converted to a period followed by an asterisk (.*). glow up.
  • period (.) β€” will be escaped by a backslash character (\.). gotta protect it, bestie. πŸ›‘οΈ
  • exclam (!) β€” gets converted to a circumflex (^) if it follows a left bracket ([). otherwise it remains unmodified. conditional queen. πŸ‘‘

and then, the finale: the whole pattern will be enclosed in a circumflex (^) as the leftmost character and a dollar sign ($) as the rightmost character. framed. iconic. periodt.


stSubstituteString β€” find & replace but make it fashion πŸ’–

stSubstituteString replaces all occurrences of substring old in original by string new. every single one. it does not skip. it does not miss.

it returns a pointer to an allocated string that is the result of this operation.

😭 if anything goes seriously wrong, it returns NULL. so like, check your returns, babe.

stStrtok β€” tokenizer energy 🧚

stStrtok considers the string string to consist of a sequence of zero or more text tokens separated by whitespace.

the first call (with pointer string specified) returns a pointer to the first character of the first token, and will have written a null character into string immediately following the returned token. yes it's editing your string in place, that's just the vibe.

the function keeps track of its position between separate calls, so that subsequent calls β€” which must be made with the string argument set to NULL β€” will work through the string immediately following that token. do not forget the NULL. i'm serious. πŸ™ˆ

in this way, subsequent calls will work through the string until no tokens remain.

when no token remains in string, a NULL pointer is returned. that's your lil signal that we're done here. ✨


stStrEnter β€” the intern table, but cute πŸ‘‘

stStrEnter adds the given string to an internal string table and returns a pointer to the appropriate string table entry.

equal strings are mapped to equal locations in the table. so like, two identical strings? same address. matching. πŸ’œ

and the payoff: equality of two strings in the string table can be checked by simple pointer comparison. no strcmp needed, bestie. just compare the pointers. fast. efficient. slay.


🌈 SEE ALSO 🌈

  • sh (1)
  • ed (1)

and that's the whole page, my love. this was sttk-1.7, dated Thu Jun 24 17:43:33 1993 β€” yeah she's vintage, she's an antique, and she still ate. πŸ’…βœ¨ go write some string code, you've got this. πŸ«ΆπŸ’–πŸŽ€

πŸ“¦ where this page comes from