This repository has been archived on 2023-09-28. You can view files and clone it, but cannot push or open issues or pull requests.
homepage/content/projects/noxos/docs/codebase/utils/string.h.md

92 lines
3.9 KiB
Markdown
Raw Normal View History

---
title: "string.h"
summary: "basic functions for string manipulation"
---
#### `string_t` - typedef
A null-terminated array of chars.
#### `string_length(string)` - function (uint32_t)
Returns the amount of chars a string has before it's null-terminator.
#### `string_compare(a, b)` - function (bool)
Returns **true** when the strings **_a_** and **_b_** are equal.
Returns **false** if they aren't equal.
#### `string_find_next(string, chr)` - function (uint32_t)
Returns the index of the next character that matches **_chr_** in **_string_**.
#### `string_find_last(string, chr)` - function (uint32_t)
Returns the index of the last character that matches **_chr_** in **_string_**.
#### `variadic_format_size(string, args)` - function (uint64_t)
Returns how long a format string with the given pattern (**_string_**) and **_args_** would be.
Useful to create a big enough buffer before formatting a string.
#### `format_size(string, ...)` - function (uint64_t)
This calls `variadic_format_size`, but instead of giving it a `va_list` you can give this function the actual arguments.
#### `variadic_format(output, string, args)` - function (void)
Formats **_string_** with **_args_** and writes the product to **_output_**.
The rules for format strings are specified on top of this document in the _General concepts_ block.
#### `format(output, string, ...)` - function (void)
This calls `variadic_format`, but instead of giving it a `va_list` you can give this function the actual arguments.
#### `string_unsigned_dec_to_alpha(string, value)` - function (void)
Converts the unsigned integer in **_value_** to an alphanumeric string.
The representation is decimal.
This string will be written into **_string_**.
#### `string_dec_to_alpha(string, value)` - function (void)
Converts the signed integer in **_value_** to an alphanumeric string.
If it is negative it will be prefixed with a hyphen.
The representation is decimal.
This string will be written into **_string_**.
#### `string_hex_8bit_to_alpha(string, value)` - function (void)
Converts the byte in **_value_** to an alphanumeric string.
The representation is hexadecimal.
This string will be written into **_string_**.
#### `string_hex_16bit_to_alpha(string, value)` - function (void)
Converts the word(16-bits) in **_value_** to an alphanumeric string.
The representation is hexadecimal.
This string will be written into **_string_**.
#### `string_hex_32bit_to_alpha(string, value)` - function (void)
Converts the dword(32-bits) in **_value_** to an alphanumeric string.
The representation is hexadecimal.
This string will be written into **_string_**.
#### `string_hex_64bit_to_alpha(string, value)` - function (void)
Converts the qword(64-bits) in **_value_** to an alphanumeric string.
The representation is hexadecimal.
This string will be written into **_string_**.
#### `string_bin_to_alpha(string, num_bits, value)` - function (void)
Converts the data in **_value_** to an alphanumeric string.
The representation is binary.
**_num_bits_** specifies how many bits, starting at the least significant bit, will be converted.
This string will be written into **_string_**.
#### `string_bool_to_alpha(string, value`) - function (void)
Converts the boolean in **_value_** to an alphanumeric string.
The representation is `true` or `false`.
This string will be written into **_string_**.
#### `string_is_char_text(chr)` - function (bool)
Returns whether the char (**_chr_**) contains text(a-z, A-Z, 0-9, special chars) or not.
#### `string_is_char_number(chr)` - function (bool)
Returns whether the char (**_chr_**) is a number(0-9) or not.
#### `string_is_char_alpha(chr)` - function (bool)
Returns whether the char (**_chr_**) is alphanumeric(a-z, A-Z, 0-9) or not.
#### `string_is_char_uppercase(chr)` - function (bool)
Returns whether the char (**_chr_**) is uppercase(A-Z) or not.
#### `string_is_char_lowercase(chr)` - function (bool)
Returns whether the char (**_chr_**) is lowercase(a-z) or not.