ustr_const(3)
π 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 byustr_assert_valid(). π¨
Note: changing this will not do anything useful unless USTR_CONF_INCLUDE_CODEONLY_HEADERS is non-zero.
USTR_CONF_USE_ASSERTβ turnsUSTR_ASSERT()calls on, so the code within them will be evaluated. Note that there are many calls toustr_assert_valid()withinUSTR_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 is1, then if they are supported by the compiler that built the library they will be used; if the value is0they won't be used at all. π οΈUSTR_CONF_COMPILE_TYPEDEFβ controls whethertypedefwill be used for the structs in the public headers for the library. If the value is1then they will be used; if the value is0they 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 tostrlen(), 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 range0-255. πUSTR_BEG_CONST2β same first-byte situation, but for a constant/read-only Ustr with length in the range0-65535. π¦USTR_BEG_CONST4β first byte of a constant/read-only Ustr, length range0-4294967295. π₯USTR_BEG_FIXED1β first byte of a fixed Ustr that has a length in the range0-255. βUSTR_BEG_FIXED2β first byte of a fixed Ustr, length range0-65535. βUSTR_BEG_FIXED4β first byte of a fixed Ustr, length range0-4294967295. βUSTR_BEG_FIXED8β first byte of a fixed Ustr, length range0-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 merely0but 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 itUSTR_TYPE_PARSE_NUM_ERR_OVERFLOWwill 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 value0, 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 theUSTR_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 than11.
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 theUSTR_FLAG_PARSE_NUM_OVERFLOWflag was passed to the parse function. π₯USTR_TYPE_PARSE_NUM_ERR_NEGATIVEβ means the number parsed from theVstrstring starts with a'-'(Hyphen) character when it is supposed to be an unsigned number. (The original page saysVstrhere, bestie β we're just relaying it.) πUSTR_TYPE_PARSE_NUM_ERR_BEG_ZEROβ means the number parsed from theVstrstring starts with a'0'(Digit Zero) character, when theUSTR_FLAG_PARSE_NUM_NO_BEG_ZEROflag was passed to the parse function. (Again:Vstrin the original.) π
π Constants to pass to ustr_split* π
USTR_FLAG_SPLIT_DEFβ default flags. This is merely0but 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.brright 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 merely0cast to(struct Ustr *), and can be used anywhereNULLwould be but "returns" the correct type. π«ΆUSTR_POOL_NULLβ this macro is merely0cast to(struct Ustr_pool *), and can be used anywhereNULLwould be but "returns" the correct type. π«ΆUSTR_TRUEβ this macro is1, but shows the intent that a boolean value is expected and not a number. βUSTR_FALSEβ this macro is0, 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 UstrType[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 UstrType[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 UstrType[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 UstrType[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 memoryType[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 memoryType[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 allocationType[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 allocationType[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 UstrType[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 UstrType[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 UstrType[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 UstrType[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 amalloc()andfree(), and so is even more costly than normal scrubbing.Parameter[1]: Flag for whether to include an explicit size in a UstrType[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 amalloc()andfree(), and so is even more costly than normal scrubbing.Parameter[1]: Flag for whether to include an explicit size in a UstrType[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 formattingType[1]:struct Ustr_cntl_fmt *- Note: As you would expect, the default values are:
vsnprintfandvsnprintf.
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 formattingType[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 poolType[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 poolType[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 callrealloc()to make data bigger, or revert to just allocating anew each time.Parameter[1]: Flag for if we should callrealloc()Type[1]:int *
USTR_POOL_LL_CNTL_SET_REALLOCβ this option will set the flag for if we callrealloc()to make data bigger, or revert to just allocating anew each time.Parameter[1]: Flag for if we should callrealloc()Type[1]:int- Note: As with
USTR_POOL_LL_CNTL_SET_FREE_CMPthis option means you can't assume that pool allocated data is never freed untilustr_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 π
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
- debian bookworm: libustr-dev 1.0.4-6.1
- ubuntu jammy: libustr-dev 1.0.4-6
- ubuntu noble: libustr-dev 1.0.4-6.1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms