qlibs:(str)

πŸ“¦
version 31 Β· 2 versions
, in alpine 3.24

πŸ’– okay so this is qlibs:(str) πŸ’–

bestie, welcome to the str page β€” it's giving allocated-string main character energy, and we're gonna go through every single function like it's a group chat ✨


✨ NAME ✨

str β€” string evaluation and comparision (yes, that's the spelling in the source, she's got character πŸ’…) for allocated strings.

🌸 SYNTAX 🌸

first things first, include the header, no cap:

#include "str.h"

then the whole function lineup, exactly as she comes:

unsigned int str_copy(char *dst, const char *src);
unsigned int str_copyb(char *dst, const char *src, unsigned int len);
unsigned int str_chr(const char *s, int c);
unsigned int str_rchr(const char *s, int c);
unsigned int str_diff(const char *s, const char *t);
unsigned int str_diffn(const char *s, const char *t, unsigned int len);
unsigned int str_equal(const char *s, const char *t);
unsigned int str_len(const char *s);
unsigned int str_start(const char *dst, const char *src);
char *str_append(char *dst, const char *s);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea on each one, bestie πŸ’–

  • str_copy β€” copies src into dst up to the first occurrance of \0 while including it. It returns the number of bytes written. If dst is smaller than src, str_copy fills up dst to its allocated size and returns the number of bytes it would have be written. (yep, that's the exact phrasing, no editing πŸ’€)
  • str_copyb β€” copies len bytes from src into dst.
  • str_chr and str_rchr β€” searches for a single character in a string (from left-to-right or from right-to-left) and returns the position of the first occurrance of c or the length len of s.
  • str_len β€” determines the length of a string. It returns the position of the first occurrance of \0 in s.
  • str_diff, str_diffn, and str_equal β€” compare two strings. str_diff and str_diffn returns negative, zero or positive, depending whether the string s[0], s[1], ..., s[n]=='\0' is ASCII lexicographically smaller than, equal to, or greater than the string t[0], t[1], ..., t[m-1]=='\0'. If the strings are different, both functions do not read bytes past the first difference. str_diffn considers the strings equal if the first n characters match.
  • str_equal β€” returns 1, if s and t match up to and including the first occurrance of \0 or returns 0 otherwise. It is the opposite of str_diff.
  • str_start β€” compares the two strings from the begining. It returns 1 if t is a prefix of s or 0 otherwise. (that's literally what the page says, bestie πŸ’…)
  • *str_append β€” appends a single byte s to out, given out is allocated with enough space.

πŸŽ€ NOTE πŸŽ€

⚠️ note tea, and this one matters: for the str_copy* and *str_append commands, dst has to have a preallocated space. Otherwise the result may be unexpected β€” do not play with her, bestie 😭

🌈 SEE ALSO 🌈


bye bestie! πŸ’– footer tea: this is qlibs:(str), page 3, and there's no date listed β€” timeless icon behavior πŸ•°οΈβœ¨

πŸ“¦ where this page comes from