ustr_const - Man Page

ustr string library constants

Synopsis

#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

Compile switch constants

Constant: USTR_CONF_INCLUDE_CODEONLY_HEADERS

Explanation:

 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.

Constant: USTR_CONF_USE_EOS_MARK

Explanation:

 This switch 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.

Constant: USTR_CONF_USE_ASSERT

Explanation:

 This switch 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.

Constant: USTR_CONF_COMPILE_USE_ATTRIBUTES

Explanation:

 This switch 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.

Constant: USTR_CONF_COMPILE_TYPEDEF

Explanation:

 This switch 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).
Constant: USTR_CONF_COMPILE_USE_INLINE

Explanation:

 This switch 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

Constant: USTR_BEG_CONST1

Explanation:

 This macro is a constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-255.

Constant: USTR_BEG_CONST2

Explanation:

 This macro is a constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-65535.

Constant: USTR_BEG_CONST4

Explanation:

 This macro is a constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-4294967295.

Constant: USTR_BEG_FIXED1

Explanation:

 This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-255.

Constant: USTR_BEG_FIXED2

Explanation:

 This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-65535.

Constant: USTR_BEG_FIXED4

Explanation:

 This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-4294967295.

Constant: USTR_BEG_FIXED8

Explanation:

 This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-18446744073709551615.

Note:

 This macro is only available if the Ustr code was compiled in a 64bit environment.

Constant: USTR_END_ALOCDx

Explanation:

 This macro is a 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.

Constant: USTR_END_CONSTx

Explanation:

 This macro is a 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.

Constant: USTR_END_FIXEDx

Explanation:

 This macro is a 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.

Constant: USTR_FLAG_PARSE_NUM_DEF

Explanation:

 Default flags, this is merely 0 but can be used as live documentation.

Constant: USTR_FLAG_PARSE_NUM_SEP

Explanation:

 This flag allows the parsing (and ignoring) of the seperator character, at arbitrary pointers in the number, so "1234" and "1_234" would both parse the same (assuming "_" is the seperator).

Constant: USTR_FLAG_PARSE_NUM_OVERFLOW

Explanation:

 This flag turns on the overflow checking, in other words without it USTR_TYPE_PARSE_NUM_ERR_OVERFLOW will never be returned as an error code.

Constant: USTR_FLAG_PARSE_NUM_SPACE

Explanation:

 This flag 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 ' '.

Constant: USTR_FLAG_PARSE_NUM_NO_BEG_ZERO

Explanation:

 This flag disallows one or more '0' (Digit Zero) characters before the number.

Constant: USTR_FLAG_PARSE_NUM_NO_BEG_PM

Explanation:

 This flag disallows a plus or a minus character before the number.

Constant: USTR_FLAG_PARSE_NUM_NO_NEGATIVE

Explanation:

 This flag disallows negative values.

Constant: USTR_FLAG_PARSE_NUM_EXACT

Explanation:

 This flag makes the parsing functions return an error if the entire string doesn't contain the number being parsed.

Constant: USTR_TYPE_PARSE_NUM_ERR_NONE

Explanation:

 This error code has the value 0, and means that no error occurred parsing the number.

Constant: USTR_TYPE_PARSE_NUM_ERR_ONLY_S

Explanation:

 This error code means that the Ustr string consisted only of spaces.

Constant: USTR_TYPE_PARSE_NUM_ERR_ONLY_SPM

Explanation:

 This error code means that the Ustr string consisted only spaces, and a plus or minus sign.

Constant: USTR_TYPE_PARSE_NUM_ERR_ONLY_SPMX

Explanation:

 This error code means that the Ustr string consisted of only spaces, a plus or minus sign and a "0x" base 16 prefix.
Constant: USTR_TYPE_PARSE_NUM_ERR_OOB

Explanation:

 This error code means that 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.

Constant: USTR_TYPE_PARSE_NUM_ERR_OVERFLOW

Explanation:

 This error code means that 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.

Constant: USTR_TYPE_PARSE_NUM_ERR_NEGATIVE

Explanation:

 This error code means that the number parsed from the Vstr string starts with a '-' (Hyphen) character when it is supposed to be an unsigned number.

Constant: USTR_TYPE_PARSE_NUM_ERR_BEG_ZERO

Explanation:

 This error code means that 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.

Constants to pass to ustr_split*

Constant: USTR_FLAG_SPLIT_DEF

Explanation:

 Default flags, this is merely 0 but can be used as live documentation.

Constant: USTR_FLAG_SPLIT_RET_SEP

Explanation:

 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.
   .br Constant: USTR_FLAG_SPLIT_RET_NON

Explanation:

 Return empty tokens. For example: splitting "a,,b" with separator "," will return the tokens {"a" "" "b"}.
Constant: USTR_FLAG_SPLIT_KEEP_CONFIG

Explanation:

 Force the returned Ustr's to have same configuration parameters as the Ustr string that is being split.

Misc constants to use in code

Constant: USTR_NULL

Explanation:

 This macro is merely 0 cast to (struct Ustr *), and can be used anywhere NULL would be but "returns" the correct type.

Constant: USTR_POOL_NULL

Explanation:

 This macro is merely 0 cast to (struct Ustr_pool *), and can be used anywhere NULL would be but "returns" the correct type.

Constant: USTR_TRUE

Explanation:

 This macro is 1, but shows the intent that a boolean value is expected and not a number.

Constant: USTR_FALSE

Explanation:

 This macro is 0, but shows the intent that a boolean value is expected and not a number.

Constants passed to ustr_cntl_opt()

Constant: USTR_CNTL_OPT_GET_REF_BYTES

Parameter[1]: Number of bytes for default reference count in Ustr
Type[1]: size_t *

Explanation:

 This option will get the default number of bytes used for a reference count when creating Ustr's.

Constant: USTR_CNTL_OPT_SET_REF_BYTES

Parameter[1]: Number of bytes for default reference count in Ustr
Type[1]: size_t

Explanation:

 This option will set the default number of bytes used for a reference count when creating Ustr's.

Note:

 For a single instance, the ustr_dupx_*() functions can be used.

Constant: USTR_CNTL_OPT_GET_HAS_SIZE

Parameter[1]: Default flag for whether to include an explicit size in a Ustr
Type[1]: int *

Explanation:

 This option will get the default flag for whether to store an explicit size in created Ustr's.

Constant: USTR_CNTL_OPT_SET_HAS_SIZE

Parameter[1]: Default flag for whether to include an explicit size in a Ustr
Type[1]: int

Explanation:

 This option will set the default flag for whether to store an explicit size in created Ustr's.

Note:

 For a single instance, the ustr_dupx_*() functions can be used.

Constant: USTR_CNTL_OPT_GET_EXACT_BYTES

Parameter[1]: Default flag for whether to exactly allocate memory
Type[1]: int *

Explanation:

 This option will get the default flag for whether to exactly allocate memory when a Ustr needs to be resized.

Constant: USTR_CNTL_OPT_SET_EXACT_BYTES

Parameter[1]: Default flag for whether to exactly allocate memory
Type[1]: int

Explanation:

 This option will set the default flag for whether to exactly allocate memory when a Ustr needs to be resized.

Note:

 For a single instance, the ustr_dupx_*() functions can be used.

Constant: USTR_CNTL_OPT_GET_MEM
Parameter[1]: Pointer to colleciton of function pointers for system allocation
Type[1]: struct Ustr_cntl_mem *

Explanation:

 This option will get the "system" allocation functions (malloc, realloc, free) for allocated Ustr's.

Note:

 As you would expect the default values are: malloc, realloc, free.

Constant: USTR_CNTL_OPT_SET_MEM
Parameter[1]: Pointer to colleciton of function pointers for system allocation
Type[1]: const struct Ustr_cntl_mem *

Explanation:

 This option will set the "system" allocation functions (malloc, realloc, free) for allocated Ustr's.

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.

Constant: USTR_CNTL_OPT_GET_MC_M_SCRUB

Parameter[1]: Flag for whether to include an explicit size in a Ustr
Type[1]: int *

Explanation:

 This option will get the flag for whether to "scrub" data allocated via. malloc check.

Note:

 Malloc check has to be enabled for this to mean anything, Ie. USTR_CNTL_MALLOC_LVL() must be positive.

Constant: USTR_CNTL_OPT_SET_MC_M_SCRUB

Parameter[1]: Flag for whether to include an explicit size in a Ustr
Type[1]: int

Explanation:

 This option will set the flag for whether to "scrub" data allocated via. malloc check.

Note:

 Malloc check has to be enabled for this to mean anything, Ie. USTR_CNTL_MALLOC_LVL() must be positive.

Constant: USTR_CNTL_OPT_GET_MC_F_SCRUB

Parameter[1]: Flag for whether to include an explicit size in a Ustr
Type[1]: int *

Explanation:

 This option will get the flag for whether to "scrub" data freed via. malloc check.

Note:

 Malloc check has to be enabled for this to mean anything, Ie. USTR_CNTL_MALLOC_LVL() must be positive.

Constant: USTR_CNTL_OPT_SET_MC_F_SCRUB

Parameter[1]: Flag for whether to include an explicit size in a Ustr
Type[1]: int

Explanation:

 This option will set the flag for whether to "scrub" data freed via. malloc check.

Note:

 Malloc check has to be enabled for this to mean anything, Ie. USTR_CNTL_MALLOC_LVL() must be positive.

Constant: USTR_CNTL_OPT_GET_MC_R_SCRUB

Parameter[1]: Flag for whether to include an explicit size in a Ustr
Type[1]: int *

Explanation:

 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.

Note:

 Malloc check has to be enabled for this to mean anything, Ie. USTR_CNTL_MALLOC_LVL() must be positive.

Constant: USTR_CNTL_OPT_SET_MC_R_SCRUB

Parameter[1]: Flag for whether to include an explicit size in a Ustr
Type[1]: int

Explanation:

 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.

Note:

 Malloc check has to be enabled for this to mean anything, Ie. USTR_CNTL_MALLOC_LVL() must be positive.

Constant: USTR_CNTL_OPT_GET_FMT
Parameter[1]: Pointer to colleciton of function pointers for system formating
Type[1]: struct Ustr_cntl_fmt *

Explanation:

 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.

Note:

 As you would expect the default values are: vsnprintf and vsnprintf

Constant: USTR_CNTL_OPT_SET_FMT
Parameter[1]: Pointer to colleciton of function pointers for system formatting
Type[1]: const struct Ustr_cntl_fmt *

Explanation:

 This option will set the system formatting functions (vsnprintf) for Ustr's.

Constants passed to ustr_pool_ll_cntl()

Constant: USTR_POOL_LL_CNTL_GET_FREE_CMP

Parameter[1]: Number of pointers to compare to in the pool
Type[1]: unsigned int *

Explanation:

 This option will get the number of comparisons done on a pool free operation.

Constant: USTR_POOL_LL_CNTL_SET_FREE_CMP

Parameter[1]: Number of pointers to compare to in the pool
Type[1]: unsigned int

Explanation:

 This option will set the number of comparisons done on a pool free operation.

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.

Constant: USTR_POOL_LL_CNTL_GET_REALLOC

Parameter[1]: Flag for if we should call realloc()
Type[1]: int *

Explanation:

 This option will get the flag for if we call realloc() to make data bigger, or revert to just allocating anew each time.

Constant: USTR_POOL_LL_CNTL_SET_REALLOC

Parameter[1]: Flag for if we should call realloc()
Type[1]: int

Explanation:

 This option will set the flag for if we call realloc() to make data bigger, or revert to just allocating anew each time.

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 areference (which will also make sure the ustr isn't modified behind your back).

See Also

ustr(3)

Referenced By

ustr(3), ustr-import(1).

05-Mar-2008 Ustr 1.0.4 Ustr String Library