libcproject
C static library easier to use than libc (C standard library).
string.h File Reference
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "convert.h"
#include "hash_map.h"
#include "types.h"
Include dependency graph for string.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

size_t string_get_length (const string_t string)
 Return the length of a string (excluding '\0'). More...
 
void string_to_uppercase (string_t string)
 Converts all the alphabetic characters in a string to uppercase. More...
 
void string_to_lowercase (string_t string)
 Converts all the alphabetic characters in a string to lowercase. More...
 
void string_replace (string_t string, char search, char replace)
 Replace all the occurrences of search value into replace value in the string. More...
 
void string_remove_character (string_t string, char search)
 Removes all the occurrences of a character in a string. More...
 
void string_trim_start (string_t string, char character)
 Removes all character from the start of a string. More...
 
void string_trim_end (string_t string, char character)
 Removes all character from the end of a string. More...
 
void string_trim (string_t string, char character)
 Removes all character from the start and end of a string. More...
 
string_t string_copy (const string_t string)
 Return the copy of a string. More...
 
void string_capitalize (string_t string)
 Capitalizes the string. More...
 
size_t string_total_occurrences_of_character (string_t string, char character)
 Returns the total number of occurrences of the given character in the string. More...
 
void string_reverse (const string_t string)
 Reverse the characters in a string. More...
 
bool string_equals (const string_t string1, const string_t string2)
 Check if two strings are equals. More...
 
bool string_get_is_integer (const string_t string)
 Check if the string is an integer. More...
 
string_tstring_split (const string_t string, char separator, size_t *result_size)
 Split a string into substrings using the specified separator and return them as an array and update the pointer result_size to the resulting size of the created array. More...
 
string_t string_join (string_t *array, const char separator, size_t array_length)
 Adds all the elements of an array into a string, separated by the specified separator string. More...
 
void string_concatenate (string_t *destination, string_t source)
 Concatenate two strings. More...
 
bool string_get_has_unique_characters (const string_t string)
 Check if a string contains only unique characters. More...
 
string_t string_substring (const string_t string, size_t index_start, size_t index_end)
 Returns the part of the string between the start and end indexes (both included). More...
 
bool string_get_is_substring (const string_t string, const string_t substring)
 Check if a string contains a substring. More...
 
string_t string_get_formatted_number (const int64_t number, string_t separator)
 Format a number to a string with specified separator. More...
 
string_t string_get_last_occurence_of_character (const string_t string, char character)
 Returns a pointer to the last occurrence of character in the string. More...
 
bool string_starts_with (const string_t string, const string_t prefix)
 Check if a string starts with a substring. More...
 
bool string_ends_with (const string_t string, const string_t prefix)
 Check if a string ends with a substring. More...
 
size_t string_position_of (const string_t string, const char character)
 Returns the position (index + 1) within the string of the first occurrence of the specified substring (0 if not found). More...
 
size_t string_last_position_of (const string_t string, const char character)
 Returns the position (index + 1) within the string of the last occurrence of the specified substring (0 if not found). More...
 
string_t string_pad_start (const string_t string, const string_t pad_string, size_t target_length)
 Pads a string with another pad_string (multiple times, if needed) until the resulting string reaches the target_length. The padding is applied from the start (left) of the string. More...
 
string_t string_zero_pad (uint64_t number, size_t places)
 Pad a number with zeros. More...
 

Function Documentation

◆ string_get_length()

size_t string_get_length ( const string_t  string)

Return the length of a string (excluding '\0').

Parameters
string
Returns
size_t
Since
v1.0.0

◆ string_to_uppercase()

void string_to_uppercase ( string_t  string)

Converts all the alphabetic characters in a string to uppercase.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_to_lowercase()

void string_to_lowercase ( string_t  string)

Converts all the alphabetic characters in a string to lowercase.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_replace()

void string_replace ( string_t  string,
char  search,
char  replace 
)

Replace all the occurrences of search value into replace value in the string.

NOTE: Mutates the string.

Parameters
string
searchA character search value.
replaceA character containing the text to replace for match.
Since
v1.0.0

◆ string_remove_character()

void string_remove_character ( string_t  string,
char  search 
)

Removes all the occurrences of a character in a string.

NOTE: Mutates the string.

Parameters
string
searchA character search value.
Since
v4.1.0

◆ string_trim_start()

void string_trim_start ( string_t  string,
char  character 
)

Removes all character from the start of a string.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_trim_end()

void string_trim_end ( string_t  string,
char  character 
)

Removes all character from the end of a string.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_trim()

void string_trim ( string_t  string,
char  character 
)

Removes all character from the start and end of a string.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_copy()

string_t string_copy ( const string_t  string)

Return the copy of a string.

Parameters
string
Returns
string_t
Since
v1.0.0

◆ string_capitalize()

void string_capitalize ( string_t  string)

Capitalizes the string.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_total_occurrences_of_character()

size_t string_total_occurrences_of_character ( string_t  string,
char  character 
)

Returns the total number of occurrences of the given character in the string.

Parameters
string
character
Returns
size_t
Since
v1.0.0

◆ string_reverse()

void string_reverse ( const string_t  string)

Reverse the characters in a string.

NOTE: Mutates the string.

Parameters
string
Since
v1.0.0

◆ string_equals()

bool string_equals ( const string_t  string1,
const string_t  string2 
)

Check if two strings are equals.

Parameters
string1
string2
Returns
true if the strings are equals.
false if the strings are not equals.
Since
v1.0.0

◆ string_get_is_integer()

bool string_get_is_integer ( const string_t  string)

Check if the string is an integer.

Parameters
string
Returns
true if the string is an integer.
false if the string is not an integer.
Since
v1.0.0

◆ string_split()

string_t* string_split ( const string_t  string,
char  separator,
size_t *  result_size 
)

Split a string into substrings using the specified separator and return them as an array and update the pointer result_size to the resulting size of the created array.

Parameters
string
separator
result_size
Returns
string_t*
Since
v1.0.0

◆ string_join()

string_t string_join ( string_t array,
const char  separator,
size_t  array_length 
)

Adds all the elements of an array into a string, separated by the specified separator string.

Parameters
array
separator
array_length
Returns
string_t
Since
v1.0.0

◆ string_concatenate()

void string_concatenate ( string_t destination,
string_t  source 
)

Concatenate two strings.

NOTE: Mutates the string destination.

Parameters
destination
source
Since
v1.0.0

◆ string_get_has_unique_characters()

bool string_get_has_unique_characters ( const string_t  string)

Check if a string contains only unique characters.

Parameters
string
Returns
true if string contains only unique characters.
false if string contains duplicate characters.
Since
v1.0.0

◆ string_substring()

string_t string_substring ( const string_t  string,
size_t  index_start,
size_t  index_end 
)

Returns the part of the string between the start and end indexes (both included).

Parameters
string
index_start
index_end
Returns
string_t
Since
v1.0.0

◆ string_get_is_substring()

bool string_get_is_substring ( const string_t  string,
const string_t  substring 
)

Check if a string contains a substring.

Parameters
string
substring
Returns
true if the string contains the substring.
false if the string does not contain the substring.
Since
v1.0.0

◆ string_get_formatted_number()

string_t string_get_formatted_number ( const int64_t  number,
string_t  separator 
)

Format a number to a string with specified separator.

Parameters
number
separator
Returns
string_t
string_get_formatted_number(1000, " ") // "1 000"
string_get_formatted_number(1000, ",") // "1,000"
string_t string_get_formatted_number(const int64_t number, string_t separator)
Format a number to a string with specified separator.
Since
v1.0.0

◆ string_get_last_occurence_of_character()

string_t string_get_last_occurence_of_character ( const string_t  string,
char  character 
)

Returns a pointer to the last occurrence of character in the string.

Parameters
string
character
Returns
string_t
Since
v1.0.0

◆ string_starts_with()

bool string_starts_with ( const string_t  string,
const string_t  prefix 
)

Check if a string starts with a substring.

Parameters
string
prefix
Returns
true if the string starts with the substring.
false if the string does not start with the substring.
Since
v1.0.0

◆ string_ends_with()

bool string_ends_with ( const string_t  string,
const string_t  prefix 
)

Check if a string ends with a substring.

Parameters
string
prefix
Returns
true if the string ends with the substring.
false if the string does not end with the substring.
Since
v1.0.0

◆ string_position_of()

size_t string_position_of ( const string_t  string,
const char  character 
)

Returns the position (index + 1) within the string of the first occurrence of the specified substring (0 if not found).

Parameters
string
substring
Returns
size_t
string_position_of("hello world", 'e') // 2
size_t string_position_of(const string_t string, const char character)
Returns the position (index + 1) within the string of the first occurrence of the specified substring...
Since
v4.2.0

◆ string_last_position_of()

size_t string_last_position_of ( const string_t  string,
const char  character 
)

Returns the position (index + 1) within the string of the last occurrence of the specified substring (0 if not found).

Parameters
string
character
Returns
size_t
string_last_position_of("hello world", 'o') // 8
size_t string_last_position_of(const string_t string, const char character)
Returns the position (index + 1) within the string of the last occurrence of the specified substring ...
Since
v4.2.0

◆ string_pad_start()

string_t string_pad_start ( const string_t  string,
const string_t  pad_string,
size_t  target_length 
)

Pads a string with another pad_string (multiple times, if needed) until the resulting string reaches the target_length. The padding is applied from the start (left) of the string.

Parameters
stringThe string to pad.
pad_stringThe string to pad the current string with, to the left.
target_length
Returns
string_t
string_pad_start("hello", " ", 10) // " hello"
string_t string_pad_start(const string_t string, const string_t pad_string, size_t target_length)
Pads a string with another pad_string (multiple times, if needed) until the resulting string reaches ...
Since
v4.3.0

◆ string_zero_pad()

string_t string_zero_pad ( uint64_t  number,
size_t  places 
)

Pad a number with zeros.

Parameters
number
places
Returns
string_t
string_zero_pad(1, 2) // "01"
string_zero_pad(10, 2) // "10"
string_t string_zero_pad(uint64_t number, size_t places)
Pad a number with zeros.
Since
v4.3.0