gd_strtok(3)
π gd_strtok β tokenise a string using the GetData parser π
okay bestie, welcome to gd_strtok(3) from the GETDATA collection, no cap. this is the little function that chops your string into lil token crumbs using the GetData parser's rules, and honestly? she's iconic. β¨
πΈ SYNOPSIS πΈ
#include <getdata.h>
char *gd_strtok(DIRFILE *dirfile, const char *string);
like... two args, one dream. π«Ά
β¨ DESCRIPTION β¨
so here's the tea π: gd_strtok() parses a string into a series of tokens, following the rules of the Dirfile metadata syntax (peep dirfile-format(5) if you wanna know the lore).
The first time you call gd_strtok(), you should pass the string you wanna parse in string. The first token gets returned to you. Then β and this is the important part, bestie, don't forget β on subsequent calls to parse that same string, string should be NULL (yes, exactly like strtok(3), the OG). Every time you call it like that, you get the next token back. π
Now for the plot twist: the way the Dirfile tokeniser behaves actually varies between Dirfile Standards Versions. The Standards Version in play is the current Version of the loaded DIRFILE dirfile. Use gd_dirfile_standards(3) to retrieve or change that value, k?
Changing the Standards Version of dirfile while you're mid-parse will affect the parsing of subsequent tokens β but it does not affect tokens that were already returned. Past tokens are past tokens, we don't revisit. π
Also: a copy of the string is cached in the dirfile object. Which means calling gd_strtok() with different dirfiles will parse different strings. Each dirfile is living her own main character era. π
π RETURN VALUE π
Upon successful completion, gd_strtok() returns a copy of the first token β if string is non-NULL β or else a subsequent token from the previously specified string, if string is NULL.
β Every single non-NULLpointer returned bygd_strtok()points to a new buffer allocated on the heap. Every. Single. One.
By default, strdup(3) is what allocates those buffers, but you can swap in an alternate memory manager by calling gd_alloc_funcs(3) before calling this function. Choose your fighter. π₯
And listen β the caller is responsible for deallocating all these buffers. That's you. That's your job now. Free your memory, bestie, it's self care. π§
If no more tokens are available, or if an error occurred, NULL is returned. And if an error happened, it'll also set the dirfile error to a non-zero error value. Possible error values are:
GD_E_ALLOCβ a memory allocation error occurred. sad girl hours. πGD_E_ARGUMENTβ there was no string to parse (i.e.stringwasNULL, but no previous call specified a string to parse). like, girl, what were you even tokenising??GD_E_BAD_DIRFILEβ the supplied dirfile was invalid. π©GD_E_FORMATβ a syntax error was found in the string. typo era, we've all been there. π
You can retrieve the dirfile error by calling gd_error(3). And if you want a descriptive error string for the last error you hit, that's a call to gd_error_string(3). β¨
π¦ HISTORY π¦
The gd_strtok() function appeared in GetData-0.8.0. a debut, a moment, a cultural reset. π
π SEE ALSO π
and that's the whole vibe! this page is living in Version 0.10.0, dated 25 December 2016, and it's filed under gd_strtok(3) β mwah, periodt. ππΈπ
π¦ where this page comes from
- debian bookworm: libgetdata-doc 0.11.0-6
- debian trixie: libgetdata-doc 0.11.0-15
- fedora 43: getdata-devel 0.11.0-13.fc43 Β· GPL-2.0-or-later
- fedora 43: getdata-devel 0.11.0-13.fc43 Β· GPL-2.0-or-later
- fedora 44: getdata-devel 0.11.0-14.fc44 Β· GPL-2.0-or-later
- fedora 44: getdata-devel 0.11.0-14.fc44 Β· GPL-2.0-or-later
- nixos 26.05: getdata 0.11.0
- nixpkgs unstable: getdata 0.11.0
- ubuntu jammy: libgetdata-doc 0.11.0-3ubuntu1
- ubuntu noble: libgetdata-doc 0.11.0-13
- ubuntu questing: libgetdata-doc 0.11.0-15
- ubuntu resolute: libgetdata-doc 0.11.0-17build1
- ubuntu stonking: libgetdata-doc 0.11.0-17build2
- Copyright (C) 2016 D. V. Wiebe
- Copyright (C) 2012, 2016 D. V. Wiebe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms