![]() |
O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
|
Dynamic string implementation. More...
#include "o2s/array.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | string_from_literal(StringLiteral) |
Allocates a string, copying the content from a C string. | |
#define | String |
Automatically free the allocated storage when going out of scope. | |
#define | string_append_literal(Self, StringLiteral) |
Copy the content of a C string to the end of this string. | |
Iterators | |
#define | string_foreach(STRING, Element) |
Iterate over each character of the string. | |
#define | string_enumerate(STRING, Element, Index) |
Iterate over each character of the string with its index. |
Typedefs | |
typedef array_t | string_t |
A string is an array of char. |
Functions | |
bool | string_is_equal (const string_t *self, const string_t *other) |
Compares the content of the 2 strings. | |
char * | string_to_cstring (string_t *self) |
Provide compatibility with legacy string functions. | |
bool | string_contains (const string_t *self, char character) |
Searches character in self . | |
bool | is_char_in_cstring (char character, const char *cstring) |
Searches character in cstring . | |
Contructors and destructors | |
string_t | string_new (void) |
Constructs an empty string. | |
string_t | string_from (const char *cstring, size_t length) |
Construct a string with an initial value. | |
void | string_clear (string_t *self) |
Release allocated resources to the system. | |
Adding characters | |
bool | string_append_char (string_t *self, char character) |
Add a single character to the back of the string. | |
bool | string_append_cstring (string_t *self, const char *cstring, size_t length) |
Add a raw character string to the back of the string. | |
bool | string_append (string_t *self, const string_t *other) |
Concatenate two strings. | |
bool | string_append_format (string_t *self, const char *format,...) |
Append a string formed in a similar manner as printf. | |
Removing characters | |
bool | string_pop (string_t *self, char *destination) |
Pop the last character. | |
bool | string_pop_n (string_t *self, char *destination, size_t count) |
Pop the count last characters. | |
string_t | string_pop_as_string (string_t *self, size_t count) |
Create a string from the count last characters. | |
bool | string_pop_front (string_t *self, char *destination) |
Pop the first character. | |
bool | string_pop_front_n (string_t *self, char *destination, size_t count) |
Pop the first count characters. | |
Capacity | |
size_t | string_length (const string_t *self) |
Number of characters in the string. | |
char * | string_get (const string_t *self, size_t index) |
The address of the character at the requested index. | |
bool | string_is_empty (const string_t *self) |
True if the string has a length of zero. | |
char * | string_end (const string_t *self) |
One-past-the-last pointer. | |
bool | string_reserve (string_t *self, size_t count) |
Ensure the underlying storage can accomodate count more characters. | |
bool | string_trim (string_t *self) |
Resize the underlying storage, for it not to take any more room that needed. | |
Transformation | |
string_t | string_map (const string_t *self, char(*function)(char)) |
Creates a copy of the string, where each character is the image through the provided function. | |
string_t | string_tolower (const string_t *self) |
Creates a copy of the string, with all alphabetic characters to lower-case. | |
string_t | string_toupper (const string_t *self) |
Creates a copy of the string, with all alphabetic characters to upper-case. | |
void | string_apply_inplace (string_t *self, char(*function)(char)) |
Replace each character by its image through the provided function. | |
void | string_tolower_inplace (string_t *self) |
Replace each alphabetic character by its lower case equivalent. | |
void | string_toupper_inplace (string_t *self) |
Replace each alphabetic character by its upper case equivalent. | |
Hashes | |
uint32_t | cstring_fnv1a_32 (const char *cstring, size_t length) |
Fowler–Noll–Vo hash function, on 32 bits. | |
uint32_t | string_fnv1a_32 (const string_t *self) |
Fowler–Noll–Vo hash function, on 32 bits. |
Dynamic string implementation.
Definition in file string.h.
#define String |
Automatically free the allocated storage when going out of scope.
In a situation where one wants to declare a string in a local scope, this "typedef" can be used for that string to release the allocated memory automatically when the variable goes out of scope.
It means this "typedef" can only be used like this:
#define string_append_literal | ( | Self, | |
StringLiteral ) |
#define string_from_literal | ( | StringLiteral | ) |
void string_apply_inplace | ( | string_t * | self, |
char(* | function )(char) ) |
Replace each character by its image through the provided function.
Possible implementation in GNU C :
void string_clear | ( | string_t * | self | ) |
Release allocated resources to the system.
Definition at line 33 of file constructors_destructors.c.
char * string_get | ( | const string_t * | self, |
size_t | index ) |