A library providing string functions and utilities in C.
Before using it, do cd c-string/ && ./setup.sh to install libraries.
#include <c-string/lib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
int main(void) {
String str = String_from("Hello, world!");
printf("%sn", str); // Works, since it is NULL terminated.
String_append(&str, "nfoo bar");
printf("%sn", str);
String str2 = String_clone(str);
assert(String_equal(str, str2)); // Identical
String_append(&str2, "nbaz");
assert(!String_equal(str, str2)); // Different, since one of them changed.
String str3 = String_slice(str2, 0, 5);
assert(!strcmp(str3, "Hello")); // You can use strcmp because it is NULL terminated.
// Always be sure to cleanup(aka. free) the strings to prevent memory leaks.
String_cleanup(str);
String_cleanup(str2);
String_cleanup(str3);
}A typedef of char *. Used to represent a vector of characters. Is mainly used to represent the underlying buffer of String but can also be used like StringBuffer in Java, std::stringstream in C++ or StringSink in AssemblyScript. Made with c-vector.
A typedef of char const *. Used to represent a string. It is NULL terminated to stay compatitible with the C standrd library.
A vector of Strings, just CVECTOR(String), mafe with c-vector. Used by String_split and String_split_by_char.
A struct describing an immutable fixed-size string.
int len: The length.char const *str: The pointer the content.Together with the functions declared below, there are other functions that operate on StringBuffer that are generated from the CVECTOR_WITH_NAME macro from c-vector.
Creates a StringBuffer from a string literal without allocating on the heap, valid only inside the scope that it is created.
char const *: A C string literal.Pushes a number of bytes one-by-one into the buffer.
StringBuffer *sb: The buffer where the bytes will be pushed.char *bytes: The pointer to the bytes that will be pushed.int n: Then number of bytes that will br pushed.CVECTOR_STATUS): Read silent-mode of c-vector.Pushes a NULL terminated string into the buffer.
StringBuffer *sb: The buffer where the string will be pushed.char *str: The string that will be pushed.CVECTOR_STATUS): Read silent-mode of c-vector.Creates a new empty String.
String): The newly created empty String.Creates a String from a string literal without allocating on the heap, valid only inside the scope that it is created.
char const *: A C string literal.Creates a new String from a chunk of bytes.
char *bytes: The pointer to the bytes that will be used as content.int n: The number of bytes that wil be used.String): The new String with the chunk if bytes as content.Creates a new String from a plain NULL terminated string.
char *str: The NULL terminated string.String): The new String with the NULL terminated string as content.String str: The string.int): The length of the string.Clones a String. Works like how strdup duplicates a NULL terminated string.
String str: The string that will be cloned.String): A new identical String.Concatenates the contents of two Strings into one.
String str1: The first string.String str2: The second string.String): A new String with the concatenated contents.Slices a segment of a String. Negative backward indexing is allowed(i.e. index -1 refers to the last item).
String str: The String from which the segment will be sliced.int fi: The start index.int li: The end index.String): The sliced segment. If fi is smaller than li or fi/li are smaller than 0 even after they are translated to psitive indices or if they are greater or equal than the length of the string, NULL will be returned.Hashes a String using the MurmurHash-2 non-cryptographic hashing function.
String str: The String that will be hashed.uint32_t): The hash of str.Appends a plain NULL terminated string at the end.
String *str: The pointer to the String variable. It will probably reallocate the string to a bigger memory location, so it needs to reassign the variable too.char *bstr: The NULL terminated string that will be appended.CVECTOR_STATUS): Read silent-mode of c-vector. On verbose-mode, it will return 1 if pushing any of the character fails, otherwise 1.Compares two Strings.
String str1,String str2: The strings that will be compared.bool): true if both Strings are equal in length and content, otherwise false.Frees the String from memory.
String str: The string that will be freed.void)Creates and returns the fixed version of a String
String str: The source.FixedString): The fixed string with the contents of the first argument.Splits a String by a character sequence.
String str: The string that will be splitted.char const *seq: The character sequence.Vector_String): The new strings that resulted from the split.Like String_split, but splits by a character instead of a sequence.
String str: The string that will be splitted.char c: The character.Vector_String): The new strings that resulted from the split.Removes the leading t, , n and