§4.2 String Function List
§4.3 String Function Descriptions
§4.3.1: char_is_slash
fstr_bool char_is_slash(
char c
)
Description
This call returns non-zero if c is \ or /.
§4.3.2: char_is_upper
fstr_bool char_is_upper(
char c
)
Description
If c is an uppercase letter this call returns true.
§4.3.3: char_is_lower
fstr_bool char_is_lower(
char c
)
Description
If c is a lower letter this call returns true.
§4.3.4: char_to_upper
char char_to_upper(
char c
)
Description
If c is a lowercase letter this call returns the uppercase equivalent, otherwise it returns c.
§4.3.5: char_to_lower
char char_to_lower(
char c
)
Description
If c is an uppercase letter this call returns the lowercase equivalent, otherwise it returns c.
§4.3.6: char_is_whitespace
fstr_bool char_is_whitespace(
char c
)
Description
This call returns non-zero if c is whitespace.
§4.3.7: char_is_alpha_numeric
fstr_bool char_is_alpha_numeric(
char c
)
Description
This call returns non-zero if c is any alphanumeric character including underscore.
§4.3.8: char_is_alpha_numeric_true
fstr_bool char_is_alpha_numeric_true(
char c
)
Description
This call returns non-zero if c is any alphanumeric character no including underscore.
§4.3.9: char_is_alpha
fstr_bool char_is_alpha(
char c
)
Description
This call returns non-zero if c is any alphabetic character including underscore.
§4.3.10: char_is_alpha_true
fstr_bool char_is_alpha_true(
char c
)
Description
This call returns non-zero if c is any alphabetic character.
§4.3.11: char_is_hex
fstr_bool char_is_hex(
char c
)
Description
This call returns non-zero if c is any valid hexadecimal digit.
§4.3.12: char_is_numeric
fstr_bool char_is_numeric(
char c
)
Description
This call returns non-zero if c is any valid decimal digit.
§4.3.13: make_string_cap
String make_string_cap(
void *str,
int32_t size,
int32_t mem_size
)
Parameters
str
The str parameter provides the of memory with which the string shall operate.
size
The size parameter expresses the initial size of the string.
If the memory does not already contain a useful string this should be zero.
mem_size
The mem_size parameter expresses the full size of the memory provided by str.
Description
This call returns the String created from the parameters.
§4.3.14: make_string
String make_string(
void *str,
int32_t size
)
Parameters
str
The str parameter provides the of memory with which the string shall operate.
size
The size parameter expresses the initial size of the string.
If the memory does not already contain a useful string this should be zero. Since this version
does not specify the size of the memory it is also assumed that this size is the maximum size
of the memory.
Description
This call returns the String created from the parameters.
§4.3.15: make_lit_string
#define make_lit_string(s)
Description
This macro takes a literal string in quotes and uses it to create a String
with the correct size and memory size. Strings created this way should usually not be mutated.
§4.3.16: make_fixed_width_string
#define make_fixed_width_string(s)
Description
This macro takes a local char array with a fixed width and uses it to create
an empty String with the correct size and memory size to operate on the array.
§4.3.17: expand_str
#define expand_str(s)
Description
This macro is a helper for any calls that take a char*,integer pair to specify a
string. This macro expands to both of those parameters from one String struct.
§4.3.18: str_size
int32_t str_size(
char *str
)
Description
This call returns the number of bytes before a null terminator starting at str.
§4.3.19: make_string_slowly
String make_string_slowly(
void *str
)
Description
This call makes a string by counting the number of bytes before a null terminator and
treating that as the size and memory size of the string.
§4.3.20: substr_tail
String substr_tail(
String str,
int32_t start
)
Description
This call creates a substring of str that starts with an offset from str's base.
The new string uses the same underlying memory so both strings will see changes.
Usually strings created this way should only go through immutable calls.
§4.3.21: substr
String substr(
String str,
int32_t start,
int32_t size
)
Description
This call creates a substring of str that starts with an offset from str's base,
and has a fixed size. The new string uses the same underlying memory so both strings
will see changes. Usually strings created this way should only go through immutable calls.
§4.3.22: skip_whitespace
String skip_whitespace(
String str
)
Description
This call creates a substring that starts with the first non-whitespace character of str.
Like other substr calls, the new string uses the underlying memory and so should usually be
considered immutable.
See Also
§4.3.23: chop_whitespace
String chop_whitespace(
String str
)
Description
This call creates a substring that ends with the last non-whitespace character of str.
Like other substr calls, the new string uses the underlying memory and so should usually be
considered immutable.
See Also
§4.3.24: skip_chop_whitespace
String skip_chop_whitespace(
String str
)
Description
This call is equivalent to calling skip_whitespace and chop_whitespace together.
See Also
§4.3.25: tailstr
String tailstr(
String str
)
Description
This call returns an empty String with underlying memory taken from
the portion of str's memory that is not used.
§4.3.26: match_cc
fstr_bool match_cc(
char *a,
char *b
)
Description
This call returns non-zero if a and b are equivalent.
§4.3.27: match_sc
fstr_bool match_sc(
String a,
char *b
)
Description
This call returns non-zero if a and b are equivalent.
§4.3.28: match_cs
fstr_bool match_cs(
char *a,
String b
)
Description
This call returns non-zero if a and b are equivalent.
§4.3.29: match_ss
fstr_bool match_ss(
String a,
String b
)
Description
This call returns non-zero if a and b are equivalent.
§4.3.30: match_part_ccl
fstr_bool match_part_ccl(
char *a,
char *b,
int32_t *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call is similar to a match call, except that it is permitted for a to be longer than b.
In other words this call returns non-zero if b is a prefix of a.
§4.3.31: match_part_scl
fstr_bool match_part_scl(
String a,
char *b,
int32_t *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call is similar to a match call, except that it is permitted for a to be longer than b.
In other words this call returns non-zero if b is a prefix of a.
§4.3.32: match_part_cc
fstr_bool match_part_cc(
char *a,
char *b
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call is similar to a match call, except that it is permitted for a to be longer than b.
In other words this call returns non-zero if b is a prefix of a.
§4.3.33: match_part_sc
fstr_bool match_part_sc(
String a,
char *b
)
Description
This call is similar to a match call, except that it is permitted for a to be longer than b.
In other words this call returns non-zero if b is a prefix of a.
§4.3.34: match_part_cs
fstr_bool match_part_cs(
char *a,
String b
)
Description
This call is similar to a match call, except that it is permitted for a to be longer than b.
In other words this call returns non-zero if b is a prefix of a.
§4.3.35: match_part_ss
fstr_bool match_part_ss(
String a,
String b
)
Description
This call is similar to a match call, except that it is permitted for a to be longer than b.
In other words this call returns non-zero if b is a prefix of a.
§4.3.36: match_insensitive_cc
fstr_bool match_insensitive_cc(
char *a,
char *b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.
§4.3.37: match_insensitive_sc
fstr_bool match_insensitive_sc(
String a,
char *b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.
§4.3.38: match_insensitive_cs
fstr_bool match_insensitive_cs(
char *a,
String b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.
§4.3.39: match_insensitive_ss
fstr_bool match_insensitive_ss(
String a,
String b
)
Description
This call returns non-zero if a and b are equivalent under case insensitive comparison.
§4.3.40: match_part_insensitive_ccl
fstr_bool match_part_insensitive_ccl(
char *a,
char *b,
int32_t *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.
See Also
§4.3.41: match_part_insensitive_scl
fstr_bool match_part_insensitive_scl(
String a,
char *b,
int32_t *len
)
Parameters
len
If this call returns non-zero this parameter is used to output the length of b.
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.
See Also
§4.3.42: match_part_insensitive_cc
fstr_bool match_part_insensitive_cc(
char *a,
char *b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.
See Also
§4.3.43: match_part_insensitive_sc
fstr_bool match_part_insensitive_sc(
String a,
char *b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.
See Also
§4.3.44: match_part_insensitive_cs
fstr_bool match_part_insensitive_cs(
char *a,
String b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.
See Also
§4.3.45: match_part_insensitive_ss
fstr_bool match_part_insensitive_ss(
String a,
String b
)
Description
This call performs the same partial matching rule as match_part under case insensitive comparison.
See Also
§4.3.46: compare_cc
int32_t compare_cc(
char *a,
char *b
)
Description
This call returns zero if a and b are equivalent,
it returns negative if a sorts before b alphabetically,
and positive if a sorts after b alphabetically.
§4.3.47: compare_sc
int32_t compare_sc(
String a,
char *b
)
Description
This call returns zero if a and b are equivalent,
it returns negative if a sorts before b alphabetically,
and positive if a sorts after b alphabetically.
§4.3.48: compare_cs
int32_t compare_cs(
char *a,
String b
)
Description
This call returns zero if a and b are equivalent,
it returns negative if a sorts before b alphabetically,
and positive if a sorts after b alphabetically.
§4.3.49: compare_ss
int32_t compare_ss(
String a,
String b
)
Description
This call returns zero if a and b are equivalent,
it returns negative if a sorts before b alphabetically,
and positive if a sorts after b alphabetically.
§4.3.50: find_c_char
int32_t find_c_char(
char *str,
int32_t start,
char character
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
character
The character parameter provides the character for which to search.
Description
This call returns the index of the first occurance of character, or the size of the string
if the character is not found.
§4.3.51: find_s_char
int32_t find_s_char(
String str,
int32_t start,
char character
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
character
The character parameter provides the character for which to search.
Description
This call returns the index of the first occurance of character, or the size of the string
if the character is not found.
§4.3.52: rfind_s_char
int32_t rfind_s_char(
String str,
int32_t start,
char character
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
character
The character parameter provides the character for which to search.
Description
This call looks for the largest index less than or equal to the start position where
the given character occurs. If the index is found it is returned otherwise -1 is returned.
§4.3.53: find_c_chars
int32_t find_c_chars(
char *str,
int32_t start,
char *characters
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
character
The characters parameter provides a null terminated array of characters for which to search.
Description
This call returns the index of the first occurance of a character in the characters array,
or the size of the string if no such character is not found.
§4.3.54: find_s_chars
int32_t find_s_chars(
String str,
int32_t start,
char *characters
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
character
The characters parameter provides a null terminated array of characters for which to search.
Description
This call returns the index of the first occurance of a character in the characters array,
or the size of the string if no such character is not found.
§4.3.55: find_substr_c
int32_t find_substr_c(
char *str,
int32_t start,
String seek
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call returns the index of the first occurance of the seek substring in str or the
size of str if no such substring in str is found.
§4.3.56: find_substr_s
int32_t find_substr_s(
String str,
int32_t start,
String seek
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call returns the index of the first occurance of the seek substring in str or the
size of str if no such substring in str is found.
§4.3.57: rfind_substr_s
int32_t rfind_substr_s(
String str,
int32_t start,
String seek
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call returns the index of the last occurance of the seek substring in str
or -1 if no such substring in str is found.
§4.3.58: find_substr_insensitive_c
int32_t find_substr_insensitive_c(
char *str,
int32_t start,
String seek
)
Parameters
str
The str parameter provides a null terminated string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call acts as find_substr under case insensitive comparison.
See Also
§4.3.59: find_substr_insensitive_s
int32_t find_substr_insensitive_s(
String str,
int32_t start,
String seek
)
Parameters
str
The str parameter provides a string to search.
start
The start parameter provides the index of the first character in str to search.
seek
The seek parameter provides a string to find in str.
Description
This call acts as find_substr under case insensitive comparison.
See Also
§4.3.60: has_substr_c
fstr_bool has_substr_c(
char *s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek.
§4.3.61: has_substr_s
fstr_bool has_substr_s(
String s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek.
§4.3.62: has_substr_insensitive_c
fstr_bool has_substr_insensitive_c(
char *s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek
under case insensitive comparison.
§4.3.63: has_substr_insensitive_s
fstr_bool has_substr_insensitive_s(
String s,
String seek
)
Description
This call returns non-zero if the string s contains a substring equivalent to seek
under case insensitive comparison.
§4.3.64: copy_fast_unsafe_cc
int32_t copy_fast_unsafe_cc(
char *dest,
char *src
)
Description
This call performs a copy from the src buffer to the dest buffer.
The copy does not stop until a null terminator is found in src. There
is no safety against overrun so dest must be large enough to contain src.
The null terminator is not written to dest. This call returns the number
of bytes coppied to dest.
§4.3.65: copy_fast_unsafe_cs
int32_t copy_fast_unsafe_cs(
char *dest,
String src
)
Description
This call performs a copy from the src string to the dest buffer.
The copy does not stop until src.size characters are coppied. There
is no safety against overrun so dest must be large enough to contain src.
The null terminator is not written to dest. This call returns the number
of bytes coppied to dest.
§4.3.66: copy_checked_ss
fstr_bool copy_checked_ss(
String *dest,
String src
)
Description
This call performs a copy from the src string to the dest string.
The memory_size of dest is checked before any coppying is done.
This call returns non-zero on a successful copy.
§4.3.67: copy_partial_sc
fstr_bool copy_partial_sc(
String *dest,
char *src
)
Description
This call performs a copy from the src buffer to the dest string.
The memory_size of dest is checked if the entire copy cannot be performed,
as many bytes as possible are coppied to dest. This call returns non-zero
if the entire string is coppied to dest.
§4.3.68: copy_partial_ss
fstr_bool copy_partial_ss(
String *dest,
String src
)
Description
This call performs a copy from the src string to the dest string.
The memory_size of dest is checked if the entire copy cannot be performed,
as many bytes as possible are coppied to dest. This call returns non-zero
if the entire string is coppied to dest.
§4.3.69: copy_cc
int32_t copy_cc(
char *dest,
char *src
)
Description
This call performs a copy from src to dest equivalent to copy_fast_unsafe.
See Also
§4.3.70: copy_ss
void copy_ss(
String *dest,
String src
)
Description
This call performs a copy from src to dest equivalent to copy_checked.
See Also
§4.3.71: copy_sc
void copy_sc(
String *dest,
char *src
)
Description
This call performs a copy from src to dest equivalent to copy_partial.
See Also
§4.3.72: append_checked_ss
fstr_bool append_checked_ss(
String *dest,
String src
)
Description
This call checks if there is enough space in dest's underlying memory
to append src onto dest. If there is src is appended and the call returns non-zero.
§4.3.73: append_partial_sc
fstr_bool append_partial_sc(
String *dest,
char *src
)
Description
This call attemps to append as much of src into the space in dest's underlying memory
as possible. If the entire string is appended the call returns non-zero.
§4.3.74: append_partial_ss
fstr_bool append_partial_ss(
String *dest,
String src
)
Description
This call attemps to append as much of src into the space in dest's underlying memory
as possible. If the entire string is appended the call returns non-zero.
§4.3.75: append_s_char
fstr_bool append_s_char(
String *dest,
char c
)
Description
This call attemps to append c onto dest. If there is space left in dest's underlying
memory the character is appended and the call returns non-zero.
§4.3.76: append_ss
fstr_bool append_ss(
String *dest,
String src
)
Description
This call is equivalent to append_partial.
See Also
§4.3.77: append_sc
fstr_bool append_sc(
String *dest,
char *src
)
Description
This call is equivalent to append_partial.
See Also
§4.3.78: terminate_with_null
fstr_bool terminate_with_null(
String *str
)
Description
This call attemps to append a null terminator onto str without effecting the
size of str. This is usually called when the time comes to pass the the string to an
API that requires a null terminator. This call returns non-zero if there was a spare
byte in the strings underlying memory.
§4.3.79: append_padding
fstr_bool append_padding(
String *dest,
char c,
int32_t target_size
)
Description
This call pads out dest so that it has a size of target_size by appending
the padding character c until the target size is achieved. This call returns
non-zero if dest does not run out of space in the underlying memory.
§4.3.80: replace_char
void replace_char(
String *str,
char replace,
char with
)
Parameters
str
The str parameter provides the string in which replacement shall be performed.
replace
The replace character specifies which character should be replaced.
with
The with character specifies what to write into the positions where replacement occurs.
Description
This call replaces all occurances of character in str with another character.
§4.3.81: to_lower_cc
void to_lower_cc(
char *src,
char *dst
)
Parameters
src
The source string to conver to lowercase. This string must be null terminated.
dst
The destination buffer to receive the converted string. This must be large
enough to contain all of src and a null terminator.
Description
Rewrites the string in src into dst with all letters lowercased. src and dst should not
overlap with the exception that src and dst may be exactly equal in order to convert the
string in place.
§4.3.82: to_lower_ss
void to_lower_ss(
String *dst,
String src
)
Parameters
dst
The destination buffer to receive the converted string.
This must have a capacity of at least the size of src.
src
The source string to conver to lowercase.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.
§4.3.83: to_lower_s
void to_lower_s(
String *str
)
Parameters
str
The string to be converted to all lowercase.
Description
This version of to_lower converts str to lowercase in place.
§4.3.84: to_upper_cc
void to_upper_cc(
char *src,
char *dst
)
Parameters
src
The source string to convert to uppercase. This string must be null terminated.
dst
The destination buffer to receive the converted string.
This must be large enough to contain all of src and a null terminator.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.
§4.3.85: to_upper_ss
void to_upper_ss(
String *dst,
String src
)
Parameters
dst
The destination buffer to receive the converted string.
This must have a capacity of at least the size of src.
src
The source string to convert to uppercase.
Description
Rewrites the string in src into dst. src and dst should not overlap with the exception
that src and dst may be exactly equal in order to convert the string in place.
§4.3.86: to_upper_s
void to_upper_s(
String *str
)
Parameters
str
The string to be converted to all uppercase.
Description
This version of to_upper converts str to uppercase in place.
§4.3.87: to_camel_cc
void to_camel_cc(
char *src,
char *dst
)
Parameters
src
The source string to convert to camel case.
dst
The destination buffer to receive the converted string.
This must be large enough to contain all of src and a null terminator.
Description
Rewrites the string in src into dst. src and dst should not overlap
with the exception that src and dst may be exactly equal in order to
convert the string in place.
§4.3.88: int_to_str_size
int32_t int_to_str_size(
int32_t x
)
Description
This call returns the number of bytes required to represent x as a string.
§4.3.89: int_to_str
fstr_bool int_to_str(
String *dest,
int32_t x
)
Description
This call writes a string representation of x into dest. If there is enough
space in dest this call returns non-zero.
§4.3.90: append_int_to_str
fstr_bool append_int_to_str(
String *dest,
int32_t x
)
Description
This call appends a string representation of x onto dest. If there is enough
space in dest this call returns non-zero.
§4.3.91: u64_to_str_size
int32_t u64_to_str_size(
uint64_t x
)
Description
This call returns the number of bytes required to represent x as a string.
§4.3.92: u64_to_str
fstr_bool u64_to_str(
String *dest,
uint64_t x
)
Description
This call writes a string representation of x into dest. If there is enough
space in dest this call returns non-zero.
§4.3.93: append_u64_to_str
fstr_bool append_u64_to_str(
String *dest,
uint64_t x
)
Description
This call appends a string representation of x onto dest. If there is enough
space in dest this call returns non-zero.
§4.3.94: float_to_str_size
int32_t float_to_str_size(
float x
)
Description
This call returns the number of bytes required to represent x as a string.
§4.3.95: append_float_to_str
fstr_bool append_float_to_str(
String *dest,
float x
)
Description
This call writes a string representation of x into dest. If there is enough
space in dest this call returns non-zero.
§4.3.96: float_to_str
fstr_bool float_to_str(
String *dest,
float x
)
Description
This call appends a string representation of x onto dest. If there is enough
space in dest this call returns non-zero.
§4.3.97: str_is_int_c
int32_t str_is_int_c(
char *str
)
Description
If str is a valid string representation of an integer, this call returns non-zero
§4.3.98: str_is_int_s
fstr_bool str_is_int_s(
String str
)
Description
If str is a valid string representation of an integer, this call returns non-zero.
§4.3.99: str_to_int_c
int32_t str_to_int_c(
char *str
)
Description
If str is a valid string representation of an integer, this call will return
the integer represented by the string. Otherwise this call returns zero.
§4.3.100: str_to_int_s
int32_t str_to_int_s(
String str
)
Description
If str represents a valid string representation of an integer, this call will return
the integer represented by the string. Otherwise this call returns zero.
§4.3.101: hexchar_to_int
int32_t hexchar_to_int(
char c
)
Description
If c is a valid hexadecimal digit [0-9a-fA-F] this call returns the value of
the integer value of the digit. Otherwise the return is some nonsense value.
§4.3.102: int_to_hexchar
char int_to_hexchar(
int32_t x
)
Description
If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit.
Otherwise the return is some nonsense value.
§4.3.103: hexstr_to_int
uint32_t hexstr_to_int(
String str
)
Description
This call interprets str has a hexadecimal representation of an integer and returns
the represented integer value.
§4.3.104: color_to_hexstr
fstr_bool color_to_hexstr(
String *s,
uint32_t color
)
Description
This call fills s with the hexadecimal representation of the color.
If there is enough memory in s to represent the color this call returns non-zero.
§4.3.105: hexstr_to_color
fstr_bool hexstr_to_color(
String s,
uint32_t *out
)
Description
This call interprets s as a color and writes the 32-bit integer representation into out.
§4.3.106: reverse_seek_slash_pos
int32_t reverse_seek_slash_pos(
String str,
int32_t pos
)
Description
This call searches for a slash in str by starting pos bytes from the end and going backwards.
§4.3.107: reverse_seek_slash
int32_t reverse_seek_slash(
String str
)
Description
This call searches for a slash in str by starting at the end and going backwards.
§4.3.108: front_of_directory
String front_of_directory(
String dir
)
Description
This call returns a substring of dir containing only the file name or
folder name furthest to the right in the directory.
See Also
§4.3.109: path_of_directory
String path_of_directory(
String dir
)
Description
This call returns a substring of dir containing the whole path except
for the final file or folder name.
See Also
§4.3.110: set_last_folder_sc
fstr_bool set_last_folder_sc(
String *dir,
char *folder_name,
char slash
)
Parameters
dir
The dir parameter is the directory string in which to set the last folder in the directory.
folder_name
The folder_name parameter is a null terminated string specifying the name to set
at the end of the directory.
slash
The slash parameter specifies what slash to use between names in the directory.
Description
This call deletes the last file name or folder name in the dir string and appends the new provided one.
If there is enough memory in dir this call returns non-zero.
§4.3.111: set_last_folder_ss
fstr_bool set_last_folder_ss(
String *dir,
String folder_name,
char slash
)
Parameters
dir
The dir parameter is the directory string in which to set the last folder in the directory.
folder_name
The folder_name parameter is a string specifying the name to set at the end of the directory.
slash
The slash parameter specifies what slash to use between names in the directory.
Description
This call deletes the last file name or folder name in the dir string and appends the new provided one.
If there is enough memory in dir this call returns non-zero.
§4.3.112: file_extension
String file_extension(
String str
)
Description
This call returns a substring containing only the file extension of the provided filename.
See Also
§4.3.113: remove_extension
fstr_bool remove_extension(
String *str
)
Description
This call attemps to delete a file extension off the end of a filename.
This call returns non-zero on success.
§4.3.114: remove_last_folder
fstr_bool remove_last_folder(
String *str
)
Description
This call attemps to delete a folder or filename off the end of a path string.
This call returns non-zero on success.
§4.3.115: string_set_match_table
fstr_bool string_set_match_table(
void *str_set,
int32_t item_size,
int32_t count,
String str,
int32_t *match_index
)
Parameters
str_set
The str_set parameter may be an array of any type.
It should point at the String in the first element of the array.
count
The item_size parameter should describe the "stride" from one String to the next, in other
words it should be the size of one element of the array.
count
The count parameter specifies the number of elements in the str_set array.
str
The str parameter specifies the string to match against the str_set.
match_index
If this call succeeds match_index is filled with the index into str_set where the match occurred.
Description
This call tries to see if str matches any of the strings in str_set. If there is a match the call
succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.
See Also
§4.3.116: string_set_match
fstr_bool string_set_match(
String *str_set,
int32_t count,
String str,
int32_t *match_index
)
Parameters
str_set
The str_set parameter is an array of String structs specifying matchable strings.
count
The count parameter specifies the number of String structs in the str_set array.
str
The str parameter specifies the string to match against the str_set.
match_index
If this call succeeds match_index is filled with the index into str_set where the match occurred.
Description
This call tries to see if str matches any of the strings in str_set. If there is a match the call
succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.
See Also
§5 Lexer Library
§5.1 Lexer Intro
The 4cpp lexer system provides a polished, fast, flexible system that takes in C/C++ and outputs a tokenization of the text data. There are two API levels. One level is setup to let you easily get a tokenization of the file. This level manages memory for you with malloc to make it as fast as possible to start getting your tokens. The second level enables deep integration by allowing control over allocation, data chunking, and output rate control.
To use the quick setup API you simply include 4cpp_lexer.h and read the documentation at
cpp_lex_file.
To use the the fancier API include 4cpp_lexer.h and read the documentation at
cpp_lex_step. If you want to be absolutely sure you are not including malloc into your program you can define FCPP_FORBID_MALLOC before the include and the "step" API will continue to work.
There are a few more features in 4cpp that are not documented yet. You are free to try to use these, but I am not totally sure they are ready yet, and when they are they will be documented.
§5.2 Lexer Function List
§5.3 Lexer Types List
§5.4 Lexer Function Descriptions
§5.4.1: cpp_get_token
Cpp_Get_Token_Result cpp_get_token(
Cpp_Token_Array *token_array_in,
int32_t pos
)
Parameters
token_array
The array of tokens from which to get a token.
pos
The position, measured in bytes, to get the token for.
Return
A Cpp_Get_Token_Result struct is returned containing the index
of a token and a flag indicating whether the pos is contained in the token
or in whitespace after the token.
Description
This call performs a binary search over all of the tokens looking
for the token that contains the specified position. If the position
is in whitespace between the tokens, the returned token index is the
index of the token immediately before the provided position. The returned
index can be -1 if the position is before the first token.
See Also
§5.4.2: cpp_lex_step
Cpp_Lex_Result cpp_lex_step(
Cpp_Lex_Data *S_ptr,
char *chunk,
int32_t size,
int32_t full_size,
Cpp_Token_Array *token_array_out,
int32_t max_tokens_out
)
Parameters
S_ptr
The lexer state. Go to the Cpp_Lex_Data section to see how to initialize the state.
chunk
The first or next chunk of the file being lexed.
size
The number of bytes in the chunk including the null terminator if the chunk ends in a null terminator.
If the chunk ends in a null terminator the system will interpret it as the end of the file.
full_size
If the final chunk is not null terminated this parameter should specify the length of the
file in bytes. To rely on an eventual null terminator use HAS_NULL_TERM for this parameter.
token_array_out
The token array structure that will receive the tokens output by the lexer.
max_tokens_out
The maximum number of tokens to be output to the token array. To rely on the
max built into the token array pass NO_OUT_LIMIT here.
Description
This call is the primary interface of the lexing system. It is quite general so it can be used in
a lot of different ways. I will explain the general rules first, and then give some examples of common
ways it might be used.
First a lexing state, Cpp_Lex_Data, must be initialized. The file to lex must be read into N contiguous chunks
of memory. An output Cpp_Token_Array must be allocated and initialized with the appropriate count and max_count
values. Then each chunk of the file must be passed to cpp_lex_step in order using the same lexing state for each call.
Every time a call to cpp_lex_step returns LexResult_NeedChunk, the next call to cpp_lex_step should use the
next chunk. If the return is some other value, the lexer hasn't finished with the current chunk and it sopped for some
other reason, so the same chunk should be used again in the next call.
If the file chunks contain a null terminator the lexer will return LexResult_Finished when it finds this character.
At this point calling the lexer again with the same state will result in an error. If you do not have a null
terminated chunk to end the file, you may instead pass the exact size in bytes of the entire file to the full_size
parameter and it will automatically handle the termination of the lexing state when it has read that many bytes.
If a full_size is specified and the system terminates for having seen that many bytes, it will return
LexResult_Finished. If a full_size is specified and a null character is read before the total number of bytes have
been read the system will still terminate as usual and return LexResult_Finished.
If the system has filled the entire output array it will return LexResult_NeedTokenMemory. When this happens if you
want to continue lexing the file you can grow the token array, or switch to a new output array and then call
cpp_lex_step again with the chunk that was being lexed and the new output. You can also specify a max_tokens_out
which is limits how many new tokens will be added to the token array. Even if token_array_out still had more space
to hold tokens, if the max_tokens_out limit is hit, the lexer will stop and return LexResult_HitTokenLimit. If this
happens there is still space left in the token array, so you can resume simply by calling cpp_lex_step again with
the same chunk and the same output array. Also note that, unlike the chunks which must only be replaced when the
system says it needs a chunk. You may switch to or modify the output array in between calls as much as you like.
The most basic use of this system is to get it all done in one big chunk and try to allocate a nearly "infinite" output
array so that it will not run out of memory. This way you can get the entire job done in one call and then just assert
to make sure it returns LexResult_Finished to you:
Cpp_Token_Array lex_file(char *file_name){
File_Data file = read_whole_file(file_name);
char *temp = (char*)malloc(4096); // hopefully big enough
Cpp_Lex_Data lex_state = cpp_lex_data_init(temp);
Cpp_Token_Array array = {0};
array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough
array.max_count = (1 << 20)/sizeof(Cpp_Token);
Cpp_Lex_Result result =
cpp_lex_step(&lex_state, file.data, file.size, file.size,
&array, NO_OUT_LIMIT);
Assert(result == LexResult_Finished);
free(temp);
return(array);
}
See Also
§5.4.3: cpp_lex_data_init
Cpp_Lex_Data cpp_lex_data_init(
char *mem_buffer
)
Parameters
mem_buffer
The memory to use for initializing the lex state's temp memory buffer.
Return
A brand new lex state ready to begin lexing a file from the beginning.
Description
Creates a new lex state in the form of a Cpp_Lex_Data struct and returns the struct.
The system needs a temporary buffer that is as long as the longest token. 4096 is usually
enough but the buffer is not checked, so to be 100% bullet proof it has to be the same length
as the file being lexed.
§5.4.4: cpp_lex_data_temp_size
int32_t cpp_lex_data_temp_size(
Cpp_Lex_Data *lex_data
)
Parameters
lex_data
The lex state from which to get the temporary buffer size.
Description
This call gets the current size of the temporary buffer in the lexer state so
that you can move to a new temporary buffer by copying the data over.
See Also
§5.4.5: cpp_lex_data_temp_read
void cpp_lex_data_temp_read(
Cpp_Lex_Data *lex_data,
char *out_buffer
)
Parameters
lex_data
The lex state from which to read the temporary buffer.
out_buffer
The buffer into which the contents of the temporary buffer will be written.
The size of the buffer must be at least the size as returned by cpp_lex_data_temp_size.
Description
This call reads the current contents of the temporary buffer.
See Also
§5.4.6: cpp_lex_data_new_temp
void cpp_lex_data_new_temp(
Cpp_Lex_Data *lex_data,
char *new_buffer
)
Parameters
lex_data
The lex state that will receive the new temporary buffer.
new_buffer
The new temporary buffer that has the same contents as the old temporary buffer.
Description
This call can be used to set a new temporary buffer for the lex state. In cases where you want to
discontinue lexing, store the state, and resume later. In such a situation it may be necessary for you
to free the temp buffer that was originally used to make the lex state. This call allows you to supply
a new temp buffer when you are ready to resume lexing.
However the new buffer needs to have the same contents the old buffer had. To ensure this you have to
use cpp_lex_data_temp_size and cpp_lex_data_temp_read to get the relevant contents of the temp buffer
before you free it.
See Also
§5.4.7: cpp_get_relex_range
Cpp_Relex_Range cpp_get_relex_range(
Cpp_Token_Array *array,
int32_t start_pos,
int32_t end_pos
)
Parameters
array
A pointer to the token array that will be modified by the relex,
this array should already contain the tokens for the previous state of the file.
start_pos
The start position of the edited region of the file.
The start and end points are based on the edited region of the file before the edit.
end_pos
The end position of the edited region of the file.
In particular, end_pos is the first character after the edited region not effected by the edit.
Thus if the edited region contained one character end_pos - start_pos should equal 1.
The start and end points are based on the edited region of the file before the edit.
§5.4.8: cpp_relex_init
Cpp_Relex_Data cpp_relex_init(
Cpp_Token_Array *array,
int32_t start_pos,
int32_t end_pos,
int32_t character_shift_amount,
char *spare
)
Parameters
array
A pointer to the token array that will be modified by the relex,
this array should already contain the tokens for the previous state of the file.
start_pos
The start position of the edited region of the file.
The start and end points are based on the edited region of the file before the edit.
end_pos
The end position of the edited region of the file.
In particular, end_pos is the first character after the edited region not effected by the edit.
Thus if the edited region contained one character end_pos - start_pos should equal 1.
The start and end points are based on the edited region of the file before the edit.
character_shift_amount
The shift in the characters after the edited region.
spare
The spare space for the lexing state.
Should be big enough to store the largest token in the file.
Return
Returns a partially initialized relex state.
Description
This call does the first setup step of initializing a relex state. To finish initializing the relex state
you must tell the state about the positioning of the first chunk it will be fed. There are two methods of doing
this, the direct method is with cpp_relex_declare_first_chunk_position, the method that is often more convenient
is with cpp_relex_is_start_chunk. If the file is not chunked the second step of initialization can be skipped.
See Also
§5.4.9: cpp_relex_start_position
int32_t cpp_relex_start_position(
Cpp_Relex_Data *S_ptr
)
Parameters
Return
Returns the first position in the file the relexer wants to read. This is usually a position slightly
earlier than the start_pos provided as the edit range.
Description
After doing the first stage of initialization this call is useful for figuring out what chunk
of the file to feed to the lexer first. It should be a chunk that contains the position returned
by this call.
See Also
§5.4.10: cpp_relex_declare_first_chunk_position
void cpp_relex_declare_first_chunk_position(
Cpp_Relex_Data *S_ptr,
int32_t position
)
Parameters
position
The start position of the first chunk that will be fed to the relex process.
Description
To initialize the relex system completely, the system needs to know how the characters in the
first file line up with the file's absolute layout. This call declares where the first chunk's start
position is in the absolute file layout, and the system infers the alignment from that. For this method
to work the starting position of the relexing needs to be inside the first chunk. To get the relexers
starting position call cpp_relex_start_position.
See Also
§5.4.11: cpp_relex_is_start_chunk
int32_t cpp_relex_is_start_chunk(
Cpp_Relex_Data *S_ptr,
char *chunk,
int32_t chunk_size
)
Parameters
chunk_size
The size of the chunk to check.
Return
Returns non-zero if the passed in chunk should be used as the first chunk for lexing.
Description
With this method, once a state is initialized, each chunk can be fed in one after the other in
the order they appear in the absolute file layout. When this call returns non-zero it means that
the chunk that was passed in on that call should be used in the first call to cpp_relex_step. If,
after trying all of the chunks, they all return zero, pass in NULL for chunk and 0 for chunk_size
to tell the system that all possible chunks have already been tried, and then use those values again
in the one and only call to cpp_relex_step.
See Also
§5.4.12: cpp_relex_step
Cpp_Lex_Result cpp_relex_step(
Cpp_Relex_Data *S_ptr,
char *chunk,
int32_t chunk_size,
int32_t full_size,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
Parameters
S_ptr
A pointer to a fully initiazed relex state.
chunk
A chunk of the edited file being relexed.
chunk_size
The size of the current chunk.
full_size
The full size of the edited file.
array
A pointer to a token array that contained the original tokens before the edit.
relex_array
A pointer to a token array for spare space. The capacity of the
relex_array determines how far the relex process can go. If it runs out, the process
can be continued if the same relex_array is extended without losing the tokens it contains.
To get an appropriate capacity for relex_array, you can get the range of tokens that the relex
operation is likely to traverse by looking at the result from cpp_get_relex_range.
Description
When a file has already been lexed, and then it is edited in a small local way,
rather than lexing the new file all over again, cpp_relex_step can try to find just
the range of tokens that need to be updated and fix them in.
First the lex state must be initialized (cpp_relex_init). Then one or more calls to
cpp_relex_step will start editing the array and filling out the relex_array. The return
value of cpp_relex_step indicates whether the relex was successful or was interrupted
and if it was interrupted, what the system needs to resume.
LexResult_Finished indicates that the relex engine finished successfully.
LexResult_NeedChunk indicates that the system needs the next chunk of the file.
LexResult_NeedTokenMemory indicates that the relex_array has reached capacity, and that
it needs to be extended if it is going to continue. Sometimes in this case it is better
to stop and just lex the entire file normally, because there are a few cases where a small
local change effects a long range of the lexers output.
The relex operation can be closed in one of two ways. If the LexResult_Finished
value has been returned by this call, then to complete the edits to the array make
sure the original array has enough capacity to store the final result by calling
cpp_relex_get_new_count. Then the operation can be finished successfully by calling
cpp_relex_complete.
Whether or not the relex process finished with LexResult_Finished the process can be
finished by calling cpp_relex_abort, which puts the array back into it's original state.
No close is necessary if getting the original array state back is not necessary.
See Also
§5.4.13: cpp_relex_get_new_count
int32_t cpp_relex_get_new_count(
Cpp_Relex_Data *S_ptr,
int32_t current_count,
Cpp_Token_Array *relex_array
)
Parameters
S_ptr
A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.
current_count
The count of tokens in the original array before the edit.
relex_array
The relex_array that was used in the cpp_relex_step call/calls.
Description
After getting a LexResult_Finished from cpp_relex_step, this call can be used to get
the size the new array will have. If the original array doesn't have enough capacity to store
the new array, it's capacity should be increased before passing to cpp_relex_complete.
§5.4.14: cpp_relex_complete
void cpp_relex_complete(
Cpp_Relex_Data *S_ptr,
Cpp_Token_Array *array,
Cpp_Token_Array *relex_array
)
Parameters
S_ptr
A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.
array
The original array being edited by cpp_relex_step calls.
relex_array
The relex_array that was filled by cpp_relex_step.
Description
After getting a LexResult_Finished from cpp_relex_step, and ensuring that
array has a large enough capacity by calling cpp_relex_get_new_count, this call
does the necessary replacement of tokens in the array to make it match the new file.
§5.4.15: cpp_relex_abort
void cpp_relex_abort(
Cpp_Relex_Data *S_ptr,
Cpp_Token_Array *array
)
Parameters
S_ptr
A pointer to a state that has gone through at least one cpp_relex_step.
array
The original array that went through cpp_relex_step to be edited.
Description
After the first call to cpp_relex_step, the array's contents may have been changed,
this call assures the array is in it's original state. After this call the relex state
is dead.
§5.4.16: cpp_make_token_array
Cpp_Token_Array cpp_make_token_array(
int32_t starting_max
)
Parameters
starting_max
The number of tokens to initialize the array with.
Return
An empty Cpp_Token_Array with memory malloc'd for storing tokens.
Description
This call allocates a Cpp_Token_Array with malloc for use in other
convenience functions. Stacks that are not allocated this way should not be
used in the convenience functions.
§5.4.17: cpp_free_token_array
void cpp_free_token_array(
Cpp_Token_Array token_array
)
Parameters
token_array
An array previously allocated by cpp_make_token_array
Description
This call frees a Cpp_Token_Array.
See Also
§5.4.18: cpp_resize_token_array
void cpp_resize_token_array(
Cpp_Token_Array *token_array,
int32_t new_max
)
Parameters
token_array
An array previously allocated by cpp_make_token_array.
new_max
The new maximum size the array should support. If this is not greater
than the current size of the array the operation is ignored.
Description
This call allocates a new memory chunk and moves the existing tokens in the array
over to the new chunk.
See Also
§5.4.19: cpp_lex_file
void cpp_lex_file(
char *data,
int32_t size,
Cpp_Token_Array *token_array_out
)
Parameters
data
The file data to be lexed in a single contiguous block.
size
The number of bytes in data.
token_array_out
The token array where the output tokens will be pushed.
This token array must be previously allocated with cpp_make_token_array
Description
Lexes an entire file and manages the interaction with the lexer system so that
it is quick and convenient to lex files.
Cpp_Token_Array lex_file(char *file_name){
File_Data file = read_whole_file(file_name);
// This array will be automatically grown if it runs
// out of memory.
Cpp_Token_Array array = cpp_make_token_array(100);
cpp_lex_file(file.data, file.size, &array);
return(array);
}
See Also
§5.5 Lexer Type Descriptions
§5.5.1: Cpp_Token_Type
enum Cpp_Token_Type;
Description
A Cpp_Token_Type classifies a token to make parsing easier. Some types are not
actually output by the lexer, but exist because parsers will also make use of token
types in their own output.
Values
CPP_PP_ERROR_MESSAGE = 21
CPP_TOKEN_KEY_MODIFIER = 23
CPP_TOKEN_KEY_QUALIFIER = 24
CPP_TOKEN_KEY_OPERATOR = 25
This type is not stored in token output from the lexer.
CPP_TOKEN_KEY_CONTROL_FLOW = 26
CPP_TOKEN_KEY_TYPE_DECLARATION = 28
CPP_TOKEN_KEY_ACCESS = 29
CPP_TOKEN_KEY_LINKAGE = 30
CPP_TOKEN_IDENTIFIER = 32
CPP_TOKEN_INTEGER_CONSTANT = 33
CPP_TOKEN_CHARACTER_CONSTANT = 34
CPP_TOKEN_FLOATING_CONSTANT = 35
CPP_TOKEN_STRING_CONSTANT = 36
CPP_TOKEN_BOOLEAN_CONSTANT = 37
CPP_TOKEN_STATIC_ASSERT = 38
CPP_TOKEN_BRACKET_OPEN = 39
CPP_TOKEN_BRACKET_CLOSE = 40
CPP_TOKEN_PARENTHESE_OPEN = 41
CPP_TOKEN_PARENTHESE_CLOSE = 42
CPP_TOKEN_BRACE_OPEN = 43
CPP_TOKEN_BRACE_CLOSE = 44
CPP_TOKEN_STAR = 47
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_AMPERSAND = 48
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_TILDE = 49
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_PLUS = 50
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_MINUS = 51
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_INCREMENT = 52
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_DECREMENT = 53
This is an 'ambiguous' token type because it requires
parsing to determine the full nature of the token.
CPP_TOKEN_POSTINC = 55
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_POSTDEC = 56
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_FUNC_STYLE_CAST = 57
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_CPP_STYLE_CAST = 58
CPP_TOKEN_CALL = 59
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_INDEX = 60
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_PREINC = 63
This token is for parser use, it is not output by the lexer.
CPP_TOKEN_PREDEC = 64
This token is for parser use, it is not output by the lexer.
CPP_TOKEN_POSITIVE = 65
This token is for parser use, it is not output by the lexer.
CPP_TOKEN_NEGAITVE = 66
This token is for parser use, it is not output by the lexer.
CPP_TOKEN_BIT_NOT = 68
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_CAST = 69
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_DEREF = 70
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_TYPE_PTR = 71
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_ADDRESS = 72
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_TYPE_REF = 73
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_NEW_ARRAY = 80
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_DELETE_ARRAY = 81
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_MUL = 84
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_ADD = 87
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_SUB = 88
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_BIT_AND = 97
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_TERNARY_QMARK = 102
CPP_TOKEN_EOF = 117
This type is for parser use, it is not output by the lexer.
CPP_TOKEN_TYPE_COUNT = 118
§5.5.2: Cpp_Token
struct Cpp_Token {
Cpp_Token_Type type;
int32_t start;
int32_t size;
uint16_t state_flags;
uint16_t flags;
};
Description
Cpp_Token represents a single lexed token.
It is the primary output of the lexing system.
Fields
type
The type field indicates the type of the token.
All tokens have a type no matter the circumstances.
start
The start field indicates the index of the first character
of this token's lexeme.
size
The size field indicates the number of bytes in this token's lexeme.
state_flags
The state_flags should not be used outside of the lexer's implementation.
flags
The flags field contains extra useful information about the token.
See Also
§5.5.3: Cpp_Token_Flag
enum Cpp_Token_Flag;
Description
The Cpp_Token_Flags are used to mark up tokens with additional information.
Values
CPP_TFLAG_PP_DIRECTIVE = 0x1
Indicates that the token is a preprocessor directive.
CPP_TFLAG_PP_BODY = 0x2
Indicates that the token is on the line of a preprocessor directive.
CPP_TFLAG_MULTILINE = 0x4
Indicates that the token spans across multiple lines. This can show up
on line comments and string literals with back slash line continuation.
CPP_TFLAG_IS_OPERATOR = 0x8
Indicates that the token is some kind of operator or punctuation like braces.
CPP_TFLAG_IS_KEYWORD = 0x10
Indicates that the token is a keyword.
§5.5.4: Cpp_Token_Array
struct Cpp_Token_Array {
Cpp_Token * tokens;
int32_t count;
int32_t max_count;
};
Description
Cpp_Token_Array is used to bundle together the common elements
of a growing array of Cpp_Tokens. To initialize it the tokens field should
point to a block of memory with a size equal to max_count*sizeof(Cpp_Token)
and the count should be initialized to zero.
Fields
tokens
The tokens field points to the memory used to store the array of tokens.
count
The count field counts how many tokens in the array are currently used.
max_count
The max_count field specifies the maximum size the count field may grow to before
the tokens array is out of space.
§5.5.5: Cpp_Get_Token_Result
struct Cpp_Get_Token_Result {
int32_t token_index;
int32_t in_whitespace;
};
Description
Cpp_Get_Token_Result is the return result of the cpp_get_token call.
Fields
token_index
The token_index field indicates which token answers the query. To get the token from
the source array
array.tokens[result.token_index]
in_whitespace
The in_whitespace field is true when the query position was actually in whitespace
after the result token.
See Also
§5.5.6: Cpp_Relex_Range
struct Cpp_Relex_Range {
int32_t start_token_index;
int32_t end_token_index;
};
Description
Cpp_Relex_Range is the return result of the cpp_get_relex_range call.
Fields
start_token_index
The index of the first token in the unedited array that needs to be relexed.
end_token_index
The index of the first token in the unedited array after the edited range
that may not need to be relexed. Sometimes a relex operation has to lex past this
position to find a token that is not effected by the edit.
See Also
§5.5.7: Cpp_Lex_Data
struct Cpp_Lex_Data { /* non-public internals */ } ;
Description
Cpp_Lex_Data represents the state of the lexer so that the system may be resumable
and the user can manage the lexer state and decide when to resume lexing with it. To create
a new lexer state call cpp_lex_data_init.
The internals of the lex state should not be treated as a part of the public API.
See Also
§5.5.8: Cpp_Lex_Result
enum Cpp_Lex_Result;
Description
Cpp_Lex_Result is returned from the lexing engine to indicate why it stopped lexing.
Values
LexResult_Finished = 0
This indicates that the system got to the end of the file and will not accept more input.
LexResult_NeedChunk = 1
This indicates that the system got to the end of an input chunk and is ready to receive the
next input chunk.
LexResult_NeedTokenMemory = 2
This indicates that the output array ran out of space to store tokens and needs to be
replaced or expanded before continuing.
LexResult_HitTokenLimit = 3
This indicates that the maximum number of output tokens as specified by the user was hit.
§5.5.9: Cpp_Relex_Data
struct Cpp_Relex_Data { /* non-public internals */ } ;
Description
Cpp_Relex_Data represents the state of the relexer so that the system may be resumable.
To create a new relex state call cpp_relex_init.
See Also