ustr_const(3)

πŸ“¦
version 1.0.4 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸŽ€ NAME πŸŽ€

okay so this is ustr_const(3) from the Ustr String Library, and it's literally a whole manual page of constants. constants only, no cap. It's giving β€œreference card that ate” energy, and we're gonna go through every single one so you can flex on your compiler. πŸ’…

ustr_const β€” ustr string library constants. That's the whole name, bestie. Short, iconic, to the point. πŸŽ€


✨ SYNOPSIS ✨

include this header and these constants are in the chat:

  #include "ustr.h"

  USTR_CONF_INCLUDE_CODEONLY_HEADERS
  USTR_CONF_USE_EOS_MARK
  USTR_CONF_USE_ASSERT
  USTR_CONF_COMPILE_USE_ATTRIBUTES
  USTR_CONF_COMPILE_TYPEDEF
  USTR_CONF_COMPILE_USE_INLINE

  USTR_BEG_CONST1
  USTR_BEG_CONST2
  USTR_BEG_CONST4
  USTR_BEG_FIXED1
  USTR_BEG_FIXED2
  USTR_BEG_FIXED4
  USTR_BEG_FIXED8
  USTR_END_ALOCDx
  USTR_END_CONSTx
  USTR_END_FIXEDx

  USTR_FLAG_PARSE_NUM_DEF
  USTR_FLAG_PARSE_NUM_SEP
  USTR_FLAG_PARSE_NUM_OVERFLOW
  USTR_FLAG_PARSE_NUM_SPACE
  USTR_FLAG_PARSE_NUM_NO_BEG_ZERO
  USTR_FLAG_PARSE_NUM_NO_BEG_PM
  USTR_FLAG_PARSE_NUM_NO_NEGATIVE
  USTR_FLAG_PARSE_NUM_EXACT
  USTR_TYPE_PARSE_NUM_ERR_NONE
  USTR_TYPE_PARSE_NUM_ERR_ONLY_S
  USTR_TYPE_PARSE_NUM_ERR_ONLY_SPM
  USTR_TYPE_PARSE_NUM_ERR_ONLY_SPMX
  USTR_TYPE_PARSE_NUM_ERR_OOB
  USTR_TYPE_PARSE_NUM_ERR_OVERFLOW
  USTR_TYPE_PARSE_NUM_ERR_NEGATIVE
  USTR_TYPE_PARSE_NUM_ERR_BEG_ZERO

  USTR_FLAG_SPLIT_DEF
  USTR_FLAG_SPLIT_RET_SEP
  USTR_FLAG_SPLIT_RET_NON
  USTR_FLAG_SPLIT_KEEP_CONFIG

  USTR_NULL
  USTR_POOL_NULL
  USTR_TRUE
  USTR_FALSE

  USTR_CNTL_OPT_GET_REF_BYTES
  USTR_CNTL_OPT_SET_REF_BYTES
  USTR_CNTL_OPT_GET_HAS_SIZE
  USTR_CNTL_OPT_SET_HAS_SIZE
  USTR_CNTL_OPT_GET_EXACT_BYTES
  USTR_CNTL_OPT_SET_EXACT_BYTES
  USTR_CNTL_OPT_GET_MEM
  USTR_CNTL_OPT_SET_MEM
  USTR_CNTL_OPT_GET_MC_M_SCRUB
  USTR_CNTL_OPT_SET_MC_M_SCRUB
  USTR_CNTL_OPT_GET_MC_F_SCRUB
  USTR_CNTL_OPT_SET_MC_F_SCRUB
  USTR_CNTL_OPT_GET_MC_R_SCRUB
  USTR_CNTL_OPT_SET_MC_R_SCRUB
  USTR_CNTL_OPT_GET_FMT
  USTR_CNTL_OPT_SET_FMT

  USTR_POOL_LL_CNTL_GET_FREE_CMP
  USTR_POOL_LL_CNTL_SET_FREE_CMP
  USTR_POOL_LL_CNTL_GET_REALLOC
  USTR_POOL_LL_CNTL_SET_REALLOC

πŸ’– DESCRIPTION πŸ’–

okay bestie, plug in, this is the long part. The page groups the constants by vibe: compile switches, fixed/read-only Ustr builders, number parsing, split flags, and misc stuff. We're keeping the order exactly. 🫢

🧚 Compile switch constants 🧚

  • USTR_CONF_INCLUDE_CODEONLY_HEADERS β€” this switch controls whether all the code will be included as inline functions. Having this be non-zero means that you don't have to link against the library. linker? never met her πŸ’…
  • USTR_CONF_USE_EOS_MARK β€” turns on End of String markers, so any bounds overflow will be noticed by ustr_assert_valid(). 🚨
Note: changing this will not do anything useful unless USTR_CONF_INCLUDE_CODEONLY_HEADERS is non-zero.
  • USTR_CONF_USE_ASSERT β€” turns USTR_ASSERT() calls on, so the code within them will be evaluated. Note that there are many calls to ustr_assert_valid() within USTR_ASSERT() macros and that call is relatively expensive. 😭
Note: changing this will not do anything useful unless USTR_CONF_INCLUDE_CODEONLY_HEADERS is non-zero.
  • USTR_CONF_COMPILE_USE_ATTRIBUTES β€” controls whether gcc type __attribute__() statements are used in the public headers headers for the library. If the value is 1, then if they are supported by the compiler that built the library they will be used; if the value is 0 they won't be used at all. πŸ› οΈ
  • USTR_CONF_COMPILE_TYPEDEF β€” controls whether typedef will be used for the structs in the public headers for the library. If the value is 1 then they will be used; if the value is 0 they won't be used at all (and your code will have to use struct tags instead -- note all libraries using ustr should compile without this option set). 🏷️
  • USTR_CONF_COMPILE_USE_INLINE β€” controls whether inline functions will be used in a few cases where the function bodies are very small. 🧚
Note: in some cases this is used so that GCC can eliminate calls to strlen(), for the *_cstr() functions.

πŸ¦‹ Constants to created fixed/read-only Ustr's πŸ¦‹

these macros are constant C-style strings that help you build fixed/read-only Ustrs. Ranges matter, so keep the numbers exactly. ✨

  • USTR_BEG_CONST1 β€” constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-255. πŸŽ€
  • USTR_BEG_CONST2 β€” same first-byte situation, but for a constant/read-only Ustr with length in the range 0-65535. πŸ¦‹
  • USTR_BEG_CONST4 β€” first byte of a constant/read-only Ustr, length range 0-4294967295. πŸ”₯
  • USTR_BEG_FIXED1 β€” first byte of a fixed Ustr that has a length in the range 0-255. ⭐
  • USTR_BEG_FIXED2 β€” first byte of a fixed Ustr, length range 0-65535. ⭐
  • USTR_BEG_FIXED4 β€” first byte of a fixed Ustr, length range 0-4294967295. ⭐
  • USTR_BEG_FIXED8 β€” first byte of a fixed Ustr, length range 0-18446744073709551615. πŸ’€
Note: this macro is only available if the Ustr code was compiled in a 64bit environment.
  • USTR_END_ALOCDx β€” constant C-style string of the last bytes of an allocated Ustr. 🫢
Note: unless USTR_CONF_USE_EOS_MARK is non-zero, this is just the NIL byte.
  • USTR_END_CONSTx β€” constant C-style string of the last bytes of a constant/read-only Ustr. 🫢
Note: unless USTR_CONF_USE_EOS_MARK is non-zero, this is just the NIL byte.
  • USTR_END_FIXEDx β€” constant C-style string of the last bytes of a fixed Ustr. 🫢
Note: unless USTR_CONF_USE_EOS_MARK is non-zero, this is just the NIL byte.

🌸 Constants to use with parsing numbers: ustr_parse_uintmaxx, etc. 🌸

  • USTR_FLAG_PARSE_NUM_DEF β€” default flags. This is merely 0 but can be used as live documentation. πŸ“
  • USTR_FLAG_PARSE_NUM_SEP β€” allows the parsing (and ignoring) of the separator character, at arbitrary pointers in the number, so "1234" and "1_234" would both parse the same (assuming "_" is the separator). πŸŽ€
  • USTR_FLAG_PARSE_NUM_OVERFLOW β€” turns on overflow checking. In other words, without it USTR_TYPE_PARSE_NUM_ERR_OVERFLOW will never be returned as an error code. 🚨
  • USTR_FLAG_PARSE_NUM_SPACE β€” allows one or more ' ' (Space) characters before the number or number prefix (Plus Sign, Hyphen). 😌
Note: other forms of whitespace don't count, this just affects ' '.
  • USTR_FLAG_PARSE_NUM_NO_BEG_ZERO β€” disallows one or more '0' (Digit Zero) characters before the number. 🚫
  • USTR_FLAG_PARSE_NUM_NO_BEG_PM β€” disallows a plus or a minus character before the number. 🚫
  • USTR_FLAG_PARSE_NUM_NO_NEGATIVE β€” disallows negative values. 🚫
  • USTR_FLAG_PARSE_NUM_EXACT β€” makes the parsing functions return an error if the entire string doesn't contain the number being parsed. 🎯
  • USTR_TYPE_PARSE_NUM_ERR_NONE β€” this error code has the value 0, and means that no error occurred parsing the number. βœ…
  • USTR_TYPE_PARSE_NUM_ERR_ONLY_S β€” means the Ustr string consisted only of spaces. 😢
  • USTR_TYPE_PARSE_NUM_ERR_ONLY_SPM β€” means the Ustr string consisted only spaces, and a plus or minus sign. 😢
  • USTR_TYPE_PARSE_NUM_ERR_ONLY_SPMX β€” means the Ustr string consisted of only spaces, a plus or minus sign and a "0x" base 16 prefix. 😢
  • USTR_TYPE_PARSE_NUM_ERR_OOB β€” means the Ustr string had characters in it that where out of bounds from the working base. 🚫
Note: without the USTR_FLAG_PARSE_NUM_EXACT, this error is ignored as soon as any number is parsed. This out of bounds includes the Ustr string "++" as well as "4A", when parsing in a base less than 11.
  • USTR_TYPE_PARSE_NUM_ERR_OVERFLOW β€” means the number parsed from the Ustr string would overflow the type it is being parsed into. This is only returned when the USTR_FLAG_PARSE_NUM_OVERFLOW flag was passed to the parse function. πŸ’₯
  • USTR_TYPE_PARSE_NUM_ERR_NEGATIVE β€” means the number parsed from the Vstr string starts with a '-' (Hyphen) character when it is supposed to be an unsigned number. (The original page says Vstr here, bestie β€” we're just relaying it.) πŸ™ˆ
  • USTR_TYPE_PARSE_NUM_ERR_BEG_ZERO β€” means the number parsed from the Vstr string starts with a '0' (Digit Zero) character, when the USTR_FLAG_PARSE_NUM_NO_BEG_ZERO flag was passed to the parse function. (Again: Vstr in the original.) πŸ™ˆ

πŸ“ Constants to pass to ustr_split* πŸ“

  • USTR_FLAG_SPLIT_DEF β€” default flags. This is merely 0 but can be used as live documentation. πŸ“
  • USTR_FLAG_SPLIT_RET_SEP β€” return the separator along with the tokens. For example, splitting "a,b," using separator "," will return the tokens "a," and "b," whereas without this flag only "a" and "b" would be returned. πŸ“
  • USTR_FLAG_SPLIT_RET_NON β€” (the original has a stray .br right before this one, lol) return empty tokens. For example: splitting "a,,b" with separator "," will return the tokens {"a" "" "b"}. 🫢
  • USTR_FLAG_SPLIT_KEEP_CONFIG β€” force the returned Ustr's to have same configuration parameters as the Ustr string that is being split. πŸ› οΈ

⭐ Misc constants to use in code ⭐

  • USTR_NULL β€” this macro is merely 0 cast to (struct Ustr *), and can be used anywhere NULL would be but "returns" the correct type. 🫢
  • USTR_POOL_NULL β€” this macro is merely 0 cast to (struct Ustr_pool *), and can be used anywhere NULL would be but "returns" the correct type. 🫢
  • USTR_TRUE β€” this macro is 1, but shows the intent that a boolean value is expected and not a number. βœ…
  • USTR_FALSE β€” this macro is 0, but shows the intent that a boolean value is expected and not a number. ❌

πŸ’… Constants passed to ustr_cntl_opt() πŸ’…

okay bestie, these are the option constants for ustr_cntl_opt() β€” think of them as the settings menu for how Ustr creates and manages stuff ✨

  • USTR_CNTL_OPT_GET_REF_BYTES β€” this option will get the default number of bytes used for a reference count when creating Ustr's.
    • Parameter[1]: Number of bytes for default reference count in Ustr
    • Type[1]: size_t *
  • USTR_CNTL_OPT_SET_REF_BYTES β€” this option will set the default number of bytes used for a reference count when creating Ustr's.
    • Parameter[1]: Number of bytes for default reference count in Ustr
    • Type[1]: size_t
    • Note: For a single instance, the ustr_dupx_*() functions can be used.
  • USTR_CNTL_OPT_GET_HAS_SIZE β€” this option will get the default flag for whether to store an explicit size in created Ustr's.
    • Parameter[1]: Default flag for whether to include an explicit size in a Ustr
    • Type[1]: int *
  • USTR_CNTL_OPT_SET_HAS_SIZE β€” this option will set the default flag for whether to store an explicit size in created Ustr's.
    • Parameter[1]: Default flag for whether to include an explicit size in a Ustr
    • Type[1]: int
    • Note: For a single instance, the ustr_dupx_*() functions can be used.
  • USTR_CNTL_OPT_GET_EXACT_BYTES β€” this option will get the default flag for whether to exactly allocate memory when a Ustr needs to be resized.
    • Parameter[1]: Default flag for whether to exactly allocate memory
    • Type[1]: int *
  • USTR_CNTL_OPT_SET_EXACT_BYTES β€” this option will set the default flag for whether to exactly allocate memory when a Ustr needs to be resized.
    • Parameter[1]: Default flag for whether to exactly allocate memory
    • Type[1]: int
    • Note: For a single instance, the ustr_dupx_*() functions can be used.
  • USTR_CNTL_OPT_GET_MEM β€” this option will get the "system" allocation functions (malloc, realloc, free) for allocated Ustr's.
    • Parameter[1]: Pointer to collection of function pointers for system allocation
    • Type[1]: struct Ustr_cntl_mem *
    • Note: As you would expect, the default values are: malloc, realloc, free.
  • USTR_CNTL_OPT_SET_MEM β€” this option will set the "system" allocation functions (malloc, realloc, free) for allocated Ustr's.
    • Parameter[1]: Pointer to collection of function pointers for system allocation
    • Type[1]: const struct Ustr_cntl_mem *
    • Note: If this option is set after a Ustr has been created, then when freeing or reallocating the existing Ustr the given functions will be used. So they must either be compatible with the default or you must ensure that nothing is allocated before they are set.
  • USTR_CNTL_OPT_GET_MC_M_SCRUB β€” this option will get the flag for whether to "scrub" data allocated via malloc check.
    • Parameter[1]: Flag for whether to include an explicit size in a Ustr
    • Type[1]: int *
    • Note: Malloc check has to be enabled for this to mean anything, i.e. USTR_CNTL_MALLOC_LVL() must be positive.
  • USTR_CNTL_OPT_SET_MC_M_SCRUB β€” this option will set the flag for whether to "scrub" data allocated via malloc check.
    • Parameter[1]: Flag for whether to include an explicit size in a Ustr
    • Type[1]: int
    • Note: Malloc check has to be enabled for this to mean anything, i.e. USTR_CNTL_MALLOC_LVL() must be positive.
  • USTR_CNTL_OPT_GET_MC_F_SCRUB β€” this option will get the flag for whether to "scrub" data freed via malloc check.
    • Parameter[1]: Flag for whether to include an explicit size in a Ustr
    • Type[1]: int *
    • Note: Malloc check has to be enabled for this to mean anything, i.e. USTR_CNTL_MALLOC_LVL() must be positive.
  • USTR_CNTL_OPT_SET_MC_F_SCRUB β€” this option will set the flag for whether to "scrub" data freed via malloc check.
    • Parameter[1]: Flag for whether to include an explicit size in a Ustr
    • Type[1]: int
    • Note: Malloc check has to be enabled for this to mean anything, i.e. USTR_CNTL_MALLOC_LVL() must be positive.
  • USTR_CNTL_OPT_GET_MC_R_SCRUB β€” this option will get the flag for whether to "scrub" data reallocated via malloc check. This is done by turning all reallocations into a malloc() and free(), and so is even more costly than normal scrubbing.
    • Parameter[1]: Flag for whether to include an explicit size in a Ustr
    • Type[1]: int *
    • Note: Malloc check has to be enabled for this to mean anything, i.e. USTR_CNTL_MALLOC_LVL() must be positive.
  • USTR_CNTL_OPT_SET_MC_R_SCRUB β€” this option will set the flag for whether to "scrub" data reallocated via malloc check. This is done by turning all reallocations into a malloc() and free(), and so is even more costly than normal scrubbing.
    • Parameter[1]: Flag for whether to include an explicit size in a Ustr
    • Type[1]: int
    • Note: Malloc check has to be enabled for this to mean anything, i.e. USTR_CNTL_MALLOC_LVL() must be positive.
  • USTR_CNTL_OPT_GET_FMT β€” this option will get the system formatting functions (vsnprintf) for Ustr's. There are two functions: the first is always called, and the second is likely called (always with the exact same arguments) if the length passed to the first call was not big enough.
    • Parameter[1]: Pointer to collection of function pointers for system formatting
    • Type[1]: struct Ustr_cntl_fmt *
    • Note: As you would expect, the default values are: vsnprintf and vsnprintf.
  • USTR_CNTL_OPT_SET_FMT β€” this option will set the system formatting functions (vsnprintf) for Ustr's.
    • Parameter[1]: Pointer to collection of function pointers for system formatting
    • Type[1]: const struct Ustr_cntl_fmt *

🌸 Constants passed to ustr_pool_ll_cntl() 🌸

these are the pool knobs, bestie β€” lowkey powerful, highkey worth understanding 🫢

  • USTR_POOL_LL_CNTL_GET_FREE_CMP β€” this option will get the number of comparisons done on a pool free operation.
    • Parameter[1]: Number of pointers to compare to in the pool
    • Type[1]: unsigned int *
  • USTR_POOL_LL_CNTL_SET_FREE_CMP β€” this option will set the number of comparisons done on a pool free operation.
    • Parameter[1]: Number of pointers to compare to in the pool
    • Type[1]: unsigned int
    • Note: The default is a small non-zero value, as it's significantly common to have very short lived ustr's ... however this doesn't mean that you can't forget to take references even with pool allocated ustrs.
  • USTR_POOL_LL_CNTL_GET_REALLOC β€” this option will get the flag for if we call realloc() to make data bigger, or revert to just allocating anew each time.
    • Parameter[1]: Flag for if we should call realloc()
    • Type[1]: int *
  • USTR_POOL_LL_CNTL_SET_REALLOC β€” this option will set the flag for if we call realloc() to make data bigger, or revert to just allocating anew each time.
    • Parameter[1]: Flag for if we should call realloc()
    • Type[1]: int
    • Note: As with USTR_POOL_LL_CNTL_SET_FREE_CMP this option means you can't assume that pool allocated data is never freed until ustr_pool_free() is called, and again it is due to there being significant speed improvements for not making that assumption. Instead of disabling this option, just take a reference (which will also make sure the ustr isn't modified behind your back).

πŸ‘€ SEE ALSO πŸ‘€

ustr(3)


that's the whole constants situation, bestie β€” you ate that πŸ’…βœ¨ this page is from Ustr 1.0.4, dated 05-Mar-2008, and it's giving iconic reference-manual energy fr fr πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from