From 1ded37b10635d726bb5e1e1f090eb8f8bee15bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Sun, 25 Jun 2023 15:03:04 +0200 Subject: [PATCH] feat!: rename types `string` to `string_t` and `byte` to `byte_t` --- README.md | 2 +- lib/character.c | 4 +-- lib/character.h | 4 +-- lib/convert.c | 22 ++++++------- lib/convert.h | 12 +++---- lib/filesystem.c | 6 ++-- lib/filesystem.h | 8 ++--- lib/string.c | 82 ++++++++++++++++++++++++------------------------ lib/string.h | 48 ++++++++++++++-------------- lib/terminal.c | 4 +-- lib/terminal.h | 2 +- main.c | 2 +- set_version.c | 4 +-- 13 files changed, 100 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index 063cd1a..be5ca2d 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ touch main.c #include "libcproject/libcproject.h" int main() { - string string_value = "Hello, world!"; // `string` is a typedef from `libcproject` + string_t string_value = "Hello, world!"; // `string_t` is a typedef from `libcproject` printf("%s\n", string_value); printf("string_length = %ld\n", string_get_length(string_value)); // `string_get_length` is a function from `libcproject` return EXIT_SUCCESS; diff --git a/lib/character.c b/lib/character.c index 1e79e93..aa53ea1 100644 --- a/lib/character.c +++ b/lib/character.c @@ -1,11 +1,11 @@ #include "character.h" -void character_append(string string_value, const char character) { +void character_append(string_t string_value, const char character) { size_t length = string_get_length(string_value); character_append_at(string_value, character, length); } -void character_append_at(string string_value, const char character, const size_t index) { +void character_append_at(string_t string_value, const char character, const size_t index) { size_t length = string_get_length(string_value); for (size_t index_string = length; index_string > index; index_string--) { string_value[index_string] = string_value[index_string - 1]; diff --git a/lib/character.h b/lib/character.h index 679bbfc..faee9bd 100644 --- a/lib/character.h +++ b/lib/character.h @@ -14,7 +14,7 @@ * @param character * @since v1.0.0 */ -void character_append(string string_value, char character); +void character_append(string_t string_value, char character); /** * @brief Append a character to a string at a specific index, assuming string points to an array with enough space. @@ -24,7 +24,7 @@ void character_append(string string_value, char character); * @param index * @since v1.0.0 */ -void character_append_at(string string_value, const char character, const size_t index); +void character_append_at(string_t string_value, const char character, const size_t index); /** * @brief Converts the character to uppercase. diff --git a/lib/convert.c b/lib/convert.c index 38e3a50..afbbb53 100644 --- a/lib/convert.c +++ b/lib/convert.c @@ -1,7 +1,7 @@ #include "convert.h" -string convert_character_to_string(const char character) { - string string = malloc(sizeof(string) * 2); +string_t convert_character_to_string(const char character) { + string_t string = malloc(sizeof(string) * 2); if (string == NULL) { exit(EXIT_FAILURE); } @@ -17,7 +17,7 @@ char convert_digit_to_character(const char digit) { return digit + '0'; } -long long convert_string_to_number(const string string_value) { +long long convert_string_to_number(const string_t string_value) { bool is_negative = string_value[0] == '-'; long long integer = 0; size_t length = string_get_length(string_value); @@ -27,13 +27,13 @@ long long convert_string_to_number(const string string_value) { return is_negative ? integer * -1 : integer; } -string convert_number_to_string(const long long integer) { +string_t convert_number_to_string(const long long integer) { if (integer == 0) { return convert_character_to_string('0'); } bool is_negative = integer < 0; size_t length = 1; - string string_value = malloc(sizeof(string) * length); + string_t string_value = malloc(sizeof(string_t) * length); if (string_value == NULL) { exit(EXIT_FAILURE); } @@ -42,17 +42,17 @@ string convert_number_to_string(const long long integer) { character_append(string_value, convert_digit_to_character(current % 10)); current = current / 10; length++; - string_value = realloc(string_value, sizeof(string) * length); + string_value = realloc(string_value, sizeof(string_t) * length); } if (is_negative) { character_append(string_value, '-'); length++; - string_value = realloc(string_value, sizeof(string) * length); + string_value = realloc(string_value, sizeof(string_t) * length); } return string_reverse(string_value); } -string convert_number_from_base_10_to_base(unsigned long long number, unsigned int base) { +string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned int base) { if (number == 0) { return "0"; } @@ -63,7 +63,7 @@ string convert_number_from_base_10_to_base(unsigned long long number, unsigned i number = number / base; index++; } - string result = malloc(sizeof(string) * (index + 1)); + string_t result = malloc(sizeof(string_t) * (index + 1)); int index_result = 0; for (int iteration = index - 1; iteration >= 0; iteration--) { int remainder = remainders[iteration]; @@ -77,7 +77,7 @@ string convert_number_from_base_10_to_base(unsigned long long number, unsigned i return result; } -int convert_number_from_base_to_base_10(string number, unsigned int base) { +int convert_number_from_base_to_base_10(string_t number, unsigned int base) { int length = string_get_length(number); int exponent = length - 1; int result = 0; @@ -96,6 +96,6 @@ int convert_number_from_base_to_base_10(string number, unsigned int base) { return result; } -string convert_number_from_base_to_another(string number, int base_from, int base_target) { +string_t convert_number_from_base_to_another(string_t number, int base_from, int base_target) { return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target); } diff --git a/lib/convert.h b/lib/convert.h index 761d830..3521e95 100644 --- a/lib/convert.h +++ b/lib/convert.h @@ -15,7 +15,7 @@ * @param character * @since v1.0.0 */ -string convert_character_to_string(const char character); +string_t convert_character_to_string(const char character); /** * @brief Convert a character to a digit. @@ -39,7 +39,7 @@ char convert_digit_to_character(const char digit); * @param string * @since v1.0.0 */ -long long convert_string_to_number(const string string_value); +long long convert_string_to_number(const string_t string_value); /** * @brief Convert a number to a string. @@ -47,7 +47,7 @@ long long convert_string_to_number(const string string_value); * @param integer * @since v1.0.0 */ -string convert_number_to_string(const long long integer); +string_t convert_number_to_string(const long long integer); /** * @brief Convert a number (base 10) to a string with a specific base. @@ -56,7 +56,7 @@ string convert_number_to_string(const long long integer); * @param base * @since v1.0.0 */ -string convert_number_from_base_10_to_base(unsigned long long number, unsigned int base); +string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned int base); /** * @brief Convert a number with a specific base to a number base 10. @@ -65,7 +65,7 @@ string convert_number_from_base_10_to_base(unsigned long long number, unsigned i * @param base * @since v1.0.0 */ -int convert_number_from_base_to_base_10(string number, unsigned int base); +int convert_number_from_base_to_base_10(string_t number, unsigned int base); /** * @brief Convert a number with a specific base to a number of specific base. @@ -75,6 +75,6 @@ int convert_number_from_base_to_base_10(string number, unsigned int base); * @param base_target * @since v1.0.0 */ -string convert_number_from_base_to_another(string number, int base_from, int base_target); +string_t convert_number_from_base_to_another(string_t number, int base_from, int base_target); #endif diff --git a/lib/filesystem.c b/lib/filesystem.c index 37436f1..50e4f68 100644 --- a/lib/filesystem.c +++ b/lib/filesystem.c @@ -1,6 +1,6 @@ #include "filesystem.h" -int filesystem_read(string path, byte **file_content, off_t *file_size) { +int filesystem_read(string_t path, byte_t **file_content, off_t *file_size) { int file_descriptor = open(path, O_RDONLY); if (file_descriptor == -1) { return -1; @@ -15,7 +15,7 @@ int filesystem_read(string path, byte **file_content, off_t *file_size) { return 0; } -int filesystem_write(string path, byte *file_content, off_t file_size) { +int filesystem_write(string_t path, byte_t *file_content, off_t file_size) { int file_descriptor = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (file_descriptor == -1) { return -1; @@ -27,7 +27,7 @@ int filesystem_write(string path, byte *file_content, off_t file_size) { return 0; } -char *filesystem_get_mimetype(string path) { +char *filesystem_get_mimetype(string_t path) { if (string_ends_with(path, ".html")) { return "text/html"; } diff --git a/lib/filesystem.h b/lib/filesystem.h index f8a3d3e..d519ba8 100644 --- a/lib/filesystem.h +++ b/lib/filesystem.h @@ -13,7 +13,7 @@ #include "string.h" -typedef uint8_t byte; +typedef uint8_t byte_t; /** * @brief Read the content of a file. @@ -26,7 +26,7 @@ typedef uint8_t byte; * @retval 0 for success. * @since v1.0.0 */ -int filesystem_read(string path, byte **file_content, off_t *file_size); +int filesystem_read(string_t path, byte_t **file_content, off_t *file_size); /** * @brief Write the content to a file. @@ -39,7 +39,7 @@ int filesystem_read(string path, byte **file_content, off_t *file_size); * @retval 0 for success. * @since v1.0.0 */ -int filesystem_write(string path, byte *file_content, off_t file_size); +int filesystem_write(string_t path, byte_t *file_content, off_t file_size); /** * @brief Get the mimetype of a file. @@ -47,6 +47,6 @@ int filesystem_write(string path, byte *file_content, off_t file_size); * @param path * @since v1.0.0 */ -string filesystem_get_mimetype(string path); +string_t filesystem_get_mimetype(string_t path); #endif diff --git a/lib/string.c b/lib/string.c index 15d5f3f..89b147f 100644 --- a/lib/string.c +++ b/lib/string.c @@ -1,6 +1,6 @@ #include "string.h" -size_t string_get_length(const string string_value) { +size_t string_get_length(const string_t string_value) { size_t length = 0; while (string_value[length] != '\0') { length++; @@ -8,9 +8,9 @@ size_t string_get_length(const string string_value) { return length; } -string string_to_uppercase(string string_value) { +string_t string_to_uppercase(string_t string_value) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -20,9 +20,9 @@ string string_to_uppercase(string string_value) { return result; } -string string_to_lowercase(string string_value) { +string_t string_to_lowercase(string_t string_value) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -32,9 +32,9 @@ string string_to_lowercase(string string_value) { return result; } -string string_replace(string string_value, char search, char replace) { +string_t string_replace(string_t string_value, char search, char replace) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -49,9 +49,9 @@ string string_replace(string string_value, char search, char replace) { return result; } -string string_trim_start(string string_value) { +string_t string_trim_start(string_t string_value) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -65,9 +65,9 @@ string string_trim_start(string string_value) { return result; } -string string_trim_end(string string_value) { +string_t string_trim_end(string_t string_value) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -81,19 +81,19 @@ string string_trim_end(string string_value) { return result; } -string string_trim(string string_value) { - string result = string_trim_start(string_value); +string_t string_trim(string_t string_value) { + string_t result = string_trim_start(string_value); result = string_trim_end(result); return result; } -string string_copy(const string string_value) { +string_t string_copy(const string_t string_value) { return string_substring(string_value, 0, string_get_length(string_value)); } -string string_capitalize(string string_value) { +string_t string_capitalize(string_t string_value) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -108,7 +108,7 @@ string string_capitalize(string string_value) { return result; } -size_t string_total_occurrences_of_character(string string_value, char character) { +size_t string_total_occurrences_of_character(string_t string_value, char character) { size_t result = 0; size_t string_length = string_get_length(string_value); for (size_t index = 0; index < string_length; index++) { @@ -120,10 +120,10 @@ size_t string_total_occurrences_of_character(string string_value, char character return result; } -string string_reverse(const string string_value) { +string_t string_reverse(const string_t string_value) { size_t string_length = string_get_length(string_value); size_t index = 0; - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -134,7 +134,7 @@ string string_reverse(const string string_value) { return result; } -bool string_equals(const string string1, const string string2) { +bool string_equals(const string_t string1, const string_t string2) { size_t string1_length = string_get_length(string1); size_t string2_length = string_get_length(string2); bool is_equal = string1_length == string2_length; @@ -146,7 +146,7 @@ bool string_equals(const string string1, const string string2) { return is_equal; } -bool string_get_is_integer(const string string_value) { +bool string_get_is_integer(const string_t string_value) { size_t index = 0; size_t string_length = string_get_length(string_value); bool is_integer = string_length >= 1; @@ -166,13 +166,13 @@ bool string_get_is_integer(const string string_value) { return is_integer; } -string* string_split(const string string_value, char separator, size_t* result_size) { +string_t* string_split(const string_t string_value, char separator, size_t* result_size) { size_t string_length = string_get_length(string_value); size_t index_string = 0; size_t index_current = 0; size_t index_result = 0; - string current = malloc(sizeof(string) * string_length); - string* result = malloc(sizeof(string*) * index_result); + string_t current = malloc(sizeof(string_t) * string_length); + string_t* result = malloc(sizeof(string_t*) * index_result); if (result == NULL || current == NULL) { exit(EXIT_FAILURE); } @@ -198,14 +198,14 @@ string* string_split(const string string_value, char separator, size_t* result_s return result; } -string string_join(string* array, const char separator, size_t array_length) { +string_t string_join(string_t* array, const char separator, size_t array_length) { size_t string_length = array_length; - string string_value = malloc(sizeof(string_value) * string_length); + string_t string_value = malloc(sizeof(string_value) * string_length); if (string_value == NULL) { exit(EXIT_FAILURE); } for (size_t index_array = 0; index_array < array_length; index_array++) { - string substring = array[index_array]; + string_t substring = array[index_array]; size_t substring_length = string_get_length(substring); string_length += substring_length; string_value = realloc(string_value, sizeof(string_value) * string_length); @@ -223,11 +223,11 @@ string string_join(string* array, const char separator, size_t array_length) { return string_value; } -string string_concatenate(string string1, string string2) { +string_t string_concatenate(string_t string1, string_t string2) { size_t string1_length = string_get_length(string1); size_t string2_length = string_get_length(string2); size_t result_length = string1_length + string2_length; - string result = malloc(sizeof(string) * result_length); + string_t result = malloc(sizeof(string_t) * result_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -240,13 +240,13 @@ string string_concatenate(string string1, string string2) { return result; } -bool string_get_has_unique_characters(const string string_value) { +bool string_get_has_unique_characters(const string_t string_value) { bool has_unique = true; size_t string_length = string_get_length(string_value); struct dictionary* characters_already_seen = dictionary_initialization(); for (size_t index = 0; index < string_length && has_unique; index++) { char character = string_value[index]; - string key = convert_character_to_string(character); + string_t key = convert_character_to_string(character); if (dictionary_contains_key(characters_already_seen, key)) { has_unique = false; } else { @@ -256,16 +256,16 @@ bool string_get_has_unique_characters(const string string_value) { return has_unique; } -string string_substring(const string string_value, size_t index_start, size_t index_end) { +string_t string_substring(const string_t string_value, size_t index_start, size_t index_end) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); for (size_t index = index_start; index <= index_end; index++) { character_append(result, string_value[index]); } return result; } -bool string_get_is_substring(const string string_value, const string substring) { +bool string_get_is_substring(const string_t string_value, const string_t substring) { bool is_substring = false; size_t string_length = string_get_length(string_value); size_t substring_length = string_get_length(substring); @@ -281,14 +281,14 @@ bool string_get_is_substring(const string string_value, const string substring) return is_substring; } -string string_get_formatted_number(const long long number, string separator) { - string number_string = convert_number_to_string(number); +string_t string_get_formatted_number(const long long number, string_t separator) { + string_t number_string = convert_number_to_string(number); bool is_negative = number_string[0] == '-'; if (is_negative) { number_string = string_substring(number_string, 1, string_get_length(number_string)); } size_t number_string_length = string_get_length(number_string); - string result = malloc(sizeof(string) * number_string_length); + string_t result = malloc(sizeof(string_t) * number_string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -313,9 +313,9 @@ string string_get_formatted_number(const long long number, string separator) { return result; } -string string_get_last_occurence_of_character(const string string_value, char character) { +string_t string_get_last_occurence_of_character(const string_t string_value, char character) { size_t string_length = string_get_length(string_value); - string result = malloc(sizeof(string) * string_length); + string_t result = malloc(sizeof(string_t) * string_length); if (result == NULL) { exit(EXIT_FAILURE); } @@ -331,7 +331,7 @@ string string_get_last_occurence_of_character(const string string_value, char ch return result; } -bool string_starts_with(const string string_value, const string prefix) { +bool string_starts_with(const string_t string_value, const string_t prefix) { bool starts_with = true; size_t prefix_length = string_get_length(prefix); for (size_t index = 0; index < prefix_length && starts_with; index++) { @@ -340,7 +340,7 @@ bool string_starts_with(const string string_value, const string prefix) { return starts_with; } -bool string_ends_with(const string string_value, const string prefix) { +bool string_ends_with(const string_t string_value, const string_t prefix) { bool ends_with = true; size_t string_length = string_get_length(string_value); size_t prefix_length = string_get_length(prefix); diff --git a/lib/string.h b/lib/string.h index cfdbe5f..dac4e4f 100644 --- a/lib/string.h +++ b/lib/string.h @@ -9,7 +9,7 @@ #include "convert.h" #include "dictionary.h" -typedef char* string; +typedef char* string_t; /** * @brief Return the length of a string (excluding '\0'). @@ -18,7 +18,7 @@ typedef char* string; * @return size_t * @since v1.0.0 */ -size_t string_get_length(const string string_value); +size_t string_get_length(const string_t string_value); /** * @brief Converts all the alphabetic characters in a string to uppercase. @@ -26,7 +26,7 @@ size_t string_get_length(const string string_value); * @param string * @since v1.0.0 */ -string string_to_uppercase(string string_value); +string_t string_to_uppercase(string_t string_value); /** * @brief Converts all the alphabetic characters in a string to lowercase. @@ -34,7 +34,7 @@ string string_to_uppercase(string string_value); * @param string * @since v1.0.0 */ -string string_to_lowercase(string string_value); +string_t string_to_lowercase(string_t string_value); /** * @brief Replace all the occurrences of search value into replace value in the string. @@ -44,7 +44,7 @@ string string_to_lowercase(string string_value); * @param replace_value A character containing the text to replace for match. * @since v1.0.0 */ -string string_replace(string string_value, char search, char replace); +string_t string_replace(string_t string_value, char search, char replace); /** * @brief Removes all whitespace from the start of a string. @@ -52,7 +52,7 @@ string string_replace(string string_value, char search, char replace); * @param string * @since v1.0.0 */ -string string_trim_start(string string_value); +string_t string_trim_start(string_t string_value); /** * @brief Removes all whitespace from the end of a string. @@ -60,7 +60,7 @@ string string_trim_start(string string_value); * @param string * @since v1.0.0 */ -string string_trim_end(string string_value); +string_t string_trim_end(string_t string_value); /** * @brief Removes all whitespace from the start and end of a string. @@ -68,7 +68,7 @@ string string_trim_end(string string_value); * @param string * @since v1.0.0 */ -string string_trim(string string_value); +string_t string_trim(string_t string_value); /** * @brief Return the copy of a string. @@ -76,7 +76,7 @@ string string_trim(string string_value); * @param string * @since v1.0.0 */ -string string_copy(const string string_value); +string_t string_copy(const string_t string_value); /** * @brief Capitalizes the string. @@ -84,7 +84,7 @@ string string_copy(const string string_value); * @param string * @since v1.0.0 */ -string string_capitalize(string string_value); +string_t string_capitalize(string_t string_value); /** * @brief Returns the total number of occurrences of the given character in the string. @@ -94,7 +94,7 @@ string string_capitalize(string string_value); * @return size_t * @since v1.0.0 */ -size_t string_total_occurrences_of_character(string string_value, char character); +size_t string_total_occurrences_of_character(string_t string_value, char character); /** * @brief Reverse the characters in an array. @@ -102,7 +102,7 @@ size_t string_total_occurrences_of_character(string string_value, char character * @param string * @since v1.0.0 */ -string string_reverse(const string string_value); +string_t string_reverse(const string_t string_value); /** * @brief Check if two strings are equals. @@ -112,7 +112,7 @@ string string_reverse(const string string_value); * @return true if the strings are equals, false otherwise. * @since v1.0.0 */ -bool string_equals(const string string1, const string string2); +bool string_equals(const string_t string1, const string_t string2); /** * @brief Check if the string is a integer. @@ -121,7 +121,7 @@ bool string_equals(const string string1, const string string2); * @return true if the string is a integer, false otherwise. * @since v1.0.0 */ -bool string_get_is_integer(const string string_value); +bool string_get_is_integer(const string_t string_value); /** * @brief 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. @@ -130,7 +130,7 @@ bool string_get_is_integer(const string string_value); * @param separator * @since v1.0.0 */ -string* string_split(const string string_value, char separator, size_t* result_size); +string_t* string_split(const string_t string_value, char separator, size_t* result_size); /** * @brief Adds all the elements of an array into a string, separated by the specified separator string. @@ -139,7 +139,7 @@ string* string_split(const string string_value, char separator, size_t* result_s * @param separator * @since v1.0.0 */ -string string_join(string* array, const char separator, size_t array_length); +string_t string_join(string_t* array, const char separator, size_t array_length); /** * @brief Concatenate two strings. @@ -148,7 +148,7 @@ string string_join(string* array, const char separator, size_t array_length); * @param string2 * @since v1.0.0 */ -string string_concatenate(string string1, string string2); +string_t string_concatenate(string_t string1, string_t string2); /** * @brief Check if a string contains only unique characters. @@ -157,7 +157,7 @@ string string_concatenate(string string1, string string2); * @return true if string contains only unique characters, false otherwise. * @since v1.0.0 */ -bool string_get_has_unique_characters(const string string); +bool string_get_has_unique_characters(const string_t string); /** * @brief Returns the part of the string between the start and end indexes (both included). @@ -167,7 +167,7 @@ bool string_get_has_unique_characters(const string string); * @param index_end * @since v1.0.0 */ -string string_substring(const string string_value, size_t index_start, size_t index_end); +string_t string_substring(const string_t string_value, size_t index_start, size_t index_end); /** * @brief Check if a string contains a substring. @@ -177,7 +177,7 @@ string string_substring(const string string_value, size_t index_start, size_t in * @return true if the string contains the substring, false otherwise. * @since v1.0.0 */ -bool string_get_is_substring(const string string_value, const string substring); +bool string_get_is_substring(const string_t string_value, const string_t substring); /** * @brief Format a number to a string with specified separator. @@ -186,7 +186,7 @@ bool string_get_is_substring(const string string_value, const string substring); * @example string_get_formatted_number(1000, " ") // "1 000" * @since v1.0.0 */ -string string_get_formatted_number(const long long number, string separator); +string_t string_get_formatted_number(const long long number, string_t separator); /** * @brief Returns a pointer to the last occurrence of character in the string. @@ -195,7 +195,7 @@ string string_get_formatted_number(const long long number, string separator); * @param character * @since v1.0.0 */ -string string_get_last_occurence_of_character(const string string_value, char character); +string_t string_get_last_occurence_of_character(const string_t string_value, char character); /** * @brief Check if a string starts with a substring. @@ -205,7 +205,7 @@ string string_get_last_occurence_of_character(const string string_value, char ch * @return true if the string starts with the substring, false otherwise. * @since v1.0.0 */ -bool string_starts_with(const string string_value, const string prefix); +bool string_starts_with(const string_t string_value, const string_t prefix); /** * @brief Check if a string ends with a substring. @@ -215,6 +215,6 @@ bool string_starts_with(const string string_value, const string prefix); * @return true if the string ends with the substring, false otherwise. * @since v1.0.0 */ -bool string_ends_with(const string string_value, const string prefix); +bool string_ends_with(const string_t string_value, const string_t prefix); #endif diff --git a/lib/terminal.c b/lib/terminal.c index c7fbb7e..87d453a 100644 --- a/lib/terminal.c +++ b/lib/terminal.c @@ -1,9 +1,9 @@ #include "terminal.h" -string terminal_input() { +string_t terminal_input() { char character; size_t length = 1; - string string_value = malloc(length * sizeof(char)); + string_t string_value = malloc(length * sizeof(char)); if (string_value == NULL) { exit(EXIT_FAILURE); } diff --git a/lib/terminal.h b/lib/terminal.h index b6bc2d6..a2a5091 100644 --- a/lib/terminal.h +++ b/lib/terminal.h @@ -16,7 +16,7 @@ * @brief Read a line from stdin. * @since v1.0.0 */ -string terminal_input(); +string_t terminal_input(); /** * @brief Print an array. diff --git a/main.c b/main.c index e20f966..b2092b3 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ #include "libcproject.h" int main() { - string string_value = "Hello, world!"; + string_t string_value = "Hello, world!"; printf("%s\n", string_value); printf("string_length = %ld\n", string_get_length(string_value)); return EXIT_SUCCESS; diff --git a/set_version.c b/set_version.c index c4c2a47..fd2c25a 100644 --- a/set_version.c +++ b/set_version.c @@ -3,12 +3,12 @@ #include "libcproject.h" -int main(int argc, string* argv) { +int main(int argc, string_t* argv) { if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return EXIT_FAILURE; } - string content = "#ifndef __LIBCPROJECT_VERSION__\n"; + string_t content = "#ifndef __LIBCPROJECT_VERSION__\n"; content = string_concatenate(content, "#define __LIBCPROJECT_VERSION__ \""); content = string_concatenate(content, argv[1]); content = string_concatenate(content, "\"\n\n");