1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

19 Commits

Author SHA1 Message Date
7683aa1db7 docs(license): add email address 2024-01-30 01:25:17 +01:00
6eee39fffb chore(release): 4.2.1 [skip ci] 2023-12-26 20:20:38 +00:00
ab9860e969 fix: markdownlint in LICENSE 2023-12-26 21:19:20 +01:00
a50773e058 chore(release): 4.2.0 [skip ci] 2023-12-26 19:47:09 +00:00
1e0bf99ef6 feat: add string_last_position_of 2023-12-26 20:40:46 +01:00
ec6e748d24 feat: add string_position_of 2023-12-26 20:30:54 +01:00
9bb21e070f build(deps): update latest 2023-12-26 19:42:12 +01:00
bb9c7a1668 Merge branch 'master' of github.com:theoludwig/libcproject 2023-10-23 23:02:35 +02:00
211648d29f chore: better Prettier config for easier reviews 2023-10-23 23:02:29 +02:00
574aeb414e chore(release): 4.1.1 [skip ci] 2023-10-13 09:07:49 +00:00
e0115dd7d9 fix: error in array_list_remove (always removed the last index and not the index given) (#6)
Co-authored-by: Maxime Rumpler <mrumpler68@gmail.com>
2023-10-13 11:04:38 +02:00
269b1f7451 chore(release): 4.1.0 [skip ci] 2023-08-10 09:06:44 +00:00
c6df05e634 refactor: avoid usage of char*, instead use string_t 2023-08-10 00:32:49 +02:00
07e2f4db45 fix: convert numbers base to another only accept unsigned integers 2023-08-09 23:29:58 +02:00
b9ba3fbff4 docs: consistency improvements 2023-08-09 21:08:15 +02:00
7ef38fa993 chore: always use apt instead of apt-get 2023-08-09 20:29:19 +02:00
f99e4941e4 fix: correct usage of malloc and sizeof for structs 2023-08-09 20:25:03 +02:00
6505e3ba49 feat: add string_remove_character 2023-08-09 20:21:33 +02:00
f0716c2e12 docs: invalid @param for character_append 2023-08-09 20:17:54 +02:00
36 changed files with 344 additions and 122 deletions

View File

@ -1,2 +1,2 @@
BasedOnStyle: 'Google' BasedOnStyle: "Google"
ColumnLimit: 0 ColumnLimit: 0

View File

@ -1,8 +1,8 @@
--- ---
name: '🐛 Bug Report' name: "🐛 Bug Report"
about: 'Report an unexpected problem or unintended behavior.' about: "Report an unexpected problem or unintended behavior."
title: '[Bug]' title: "[Bug]"
labels: 'bug' labels: "bug"
--- ---
<!-- <!--

View File

@ -1,8 +1,8 @@
--- ---
name: '📜 Documentation' name: "📜 Documentation"
about: 'Correct spelling errors, improvements or additions to documentation files (README, CONTRIBUTING...).' about: "Correct spelling errors, improvements or additions to documentation files (README, CONTRIBUTING...)."
title: '[Documentation]' title: "[Documentation]"
labels: 'documentation' labels: "documentation"
--- ---
<!-- Please make sure your issue has not already been fixed. --> <!-- Please make sure your issue has not already been fixed. -->

View File

@ -1,8 +1,8 @@
--- ---
name: '✨ Feature Request' name: "✨ Feature Request"
about: 'Suggest a new feature idea.' about: "Suggest a new feature idea."
title: '[Feature]' title: "[Feature]"
labels: 'feature request' labels: "feature request"
--- ---
<!-- Please make sure your issue has not already been fixed. --> <!-- Please make sure your issue has not already been fixed. -->

View File

@ -1,8 +1,8 @@
--- ---
name: '🔧 Improvement' name: "🔧 Improvement"
about: 'Improve structure/format/performance/refactor/tests of the code.' about: "Improve structure/format/performance/refactor/tests of the code."
title: '[Improvement]' title: "[Improvement]"
labels: 'improvement' labels: "improvement"
--- ---
<!-- Please make sure your issue has not already been fixed. --> <!-- Please make sure your issue has not already been fixed. -->

View File

@ -1,8 +1,8 @@
--- ---
name: '🙋 Question' name: "🙋 Question"
about: 'Further information is requested.' about: "Further information is requested."
title: '[Question]' title: "[Question]"
labels: 'question' labels: "question"
--- ---
### Question ### Question

View File

@ -1,4 +1,4 @@
name: 'CI' name: "CI"
on: on:
push: push:
@ -8,33 +8,33 @@ on:
jobs: jobs:
ci: ci:
runs-on: 'ubuntu-latest' runs-on: "ubuntu-latest"
steps: steps:
- uses: 'actions/checkout@v3.5.3' - uses: "actions/checkout@v4.1.1"
- run: 'sudo apt update' - run: "sudo apt update"
- name: 'Install Build Tools' - name: "Install Build Tools"
run: 'sudo apt-get install --yes build-essential gcc make clang-format' run: "sudo apt install --yes build-essential gcc make clang-format"
- name: 'Install Documentation Tools' - name: "Install Documentation Tools"
run: 'sudo apt-get install --yes doxygen doxygen-gui doxygen-doc graphviz' run: "sudo apt install --yes doxygen doxygen-gui doxygen-doc graphviz"
- run: 'gcc --version' - run: "gcc --version"
- run: 'make' - run: "make"
- run: 'make run' - run: "make run"
- run: 'make test' - run: "make test"
- run: 'make lint' - run: "make lint"
- run: 'make documentation' - run: "make documentation"
- run: 'make set_version' - run: "make set_version"
- run: 'make clean' - run: "make clean"
lint-commit: lint-commit:
runs-on: 'ubuntu-latest' runs-on: "ubuntu-latest"
steps: steps:
- uses: 'actions/checkout@v3.5.3' - uses: "actions/checkout@v4.1.1"
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: 'wagoid/commitlint-github-action@v5.4.1' - uses: "wagoid/commitlint-github-action@v5.4.4"

View File

@ -1,4 +1,4 @@
name: 'Release' name: "Release"
on: on:
push: push:
@ -6,52 +6,52 @@ on:
jobs: jobs:
release: release:
runs-on: 'ubuntu-latest' runs-on: "ubuntu-latest"
steps: steps:
- uses: 'actions/checkout@v3.5.3' - uses: "actions/checkout@v4.1.1"
with: with:
fetch-depth: 0 fetch-depth: 0
persist-credentials: false persist-credentials: false
submodules: recursive submodules: "recursive"
- name: 'Import GPG key' - name: "Import GPG key"
uses: 'crazy-max/ghaction-import-gpg@v5.3.0' uses: "crazy-max/ghaction-import-gpg@v6.1.0"
with: with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
git_user_signingkey: true git_user_signingkey: true
git_commit_gpgsign: true git_commit_gpgsign: true
- run: 'sudo apt update' - run: "sudo apt update"
- name: 'Install Build Tools' - name: "Install Build Tools"
run: 'sudo apt-get install --yes build-essential gcc make clang-format' run: "sudo apt install --yes build-essential gcc make clang-format"
- name: 'Install Documentation Tools' - name: "Install Documentation Tools"
run: 'sudo apt-get install --yes doxygen doxygen-gui doxygen-doc graphviz' run: "sudo apt install --yes doxygen doxygen-gui doxygen-doc graphviz"
- run: 'make set_version' - run: "make set_version"
- name: 'Use Node.js' - name: "Use Node.js"
uses: 'actions/setup-node@v3.7.0' uses: "actions/setup-node@v4.0.1"
with: with:
node-version: '18.17.0' node-version: "20.10.0"
- name: 'Install Release Tools' - name: "Install Release Tools"
run: 'npm install --save-dev semantic-release@21.0.7 @commitlint/cli@17.6.7 @commitlint/config-conventional@17.6.7 @semantic-release/git@10.0.1 @semantic-release/exec@6.0.3 @saithodev/semantic-release-backmerge@3.2.0 vercel@31.2.2' run: "npm install --save-dev semantic-release@22.0.12 @commitlint/cli@18.4.3 @commitlint/config-conventional@18.4.3 @semantic-release/git@10.0.1 @semantic-release/exec@6.0.3 @saithodev/semantic-release-backmerge@4.0.1 vercel@33.0.1"
- run: 'rm --force package.json package-lock.json' - run: "rm --force package.json package-lock.json"
- name: 'Release' - name: "Release"
run: 'npx semantic-release' run: "npx semantic-release"
env: env:
GH_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_NAME }} GIT_COMMITTER_NAME: ${{ secrets.GIT_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_EMAIL }} GIT_COMMITTER_EMAIL: ${{ secrets.GIT_EMAIL }}
- name: 'Generate Documentation' - name: "Generate Documentation"
run: 'make documentation' run: "make documentation"
- name: 'Deploy to Vercel' - name: "Deploy to Vercel"
run: 'npx vercel ./documentation/html --token="${VERCEL_TOKEN}" --prod' run: 'npx vercel ./documentation/html --token="${VERCEL_TOKEN}" --prod'
env: env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

View File

@ -1,6 +1,6 @@
MIT License # MIT License
Copyright (c) Théo LUDWIG Copyright (c) Théo LUDWIG <contact@theoludwig.fr>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -5,11 +5,11 @@
</p> </p>
<p align="center"> <p align="center">
<a href="./CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" /></a> <a href="./CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="Contributing" /></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a> <a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a>
<a href="./CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a> <a href="./CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a>
<br /> <br />
<a href="https://github.com/theoludwig/libcproject/actions/workflows/ci.yml"><img src="https://github.com/theoludwig/libcproject/actions/workflows/ci.yml/badge.svg?branch=develop" /></a> <a href="https://github.com/theoludwig/libcproject/actions/workflows/ci.yml"><img src="https://github.com/theoludwig/libcproject/actions/workflows/ci.yml/badge.svg?branch=develop" alt="CI" /></a>
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a> <a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a>
<a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a> <a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a>
</p> </p>
@ -37,10 +37,10 @@ For example on GNU/Linux Ubuntu:
```sh ```sh
# Install Build Tools # Install Build Tools
sudo apt-get install build-essential gcc make clang-format sudo apt install build-essential gcc make clang-format
# Install Documentation Tools # Install Documentation Tools
sudo apt-get install doxygen doxygen-gui doxygen-doc graphviz sudo apt install doxygen doxygen-gui doxygen-doc graphviz
``` ```
## Usage ## Usage

View File

@ -25,8 +25,8 @@ void array_list_remove(struct array_list* list, size_t index) {
if (index >= list->size) { if (index >= list->size) {
return; return;
} }
for (size_t i = index + 1; i < list->size - 1; i++) { for (size_t i = index; i < list->size - 1; i++) {
list->data[i - 1] = list->data[i]; list->data[i] = list->data[i + 1];
} }
list->size--; list->size--;
} }

View File

@ -27,24 +27,36 @@ struct array_list* array_list_initialization();
/** /**
* @brief Adds an element to the end of the array list. * @brief Adds an element to the end of the array list.
*
* @param list
* @param element
* @since v1.2.0 * @since v1.2.0
*/ */
void array_list_add(struct array_list* list, void* element); void array_list_add(struct array_list* list, void* element);
/** /**
* @brief Removes an element from the array list. * @brief Removes an element from the array list.
*
* @param list
* @param index
* @since v1.2.0 * @since v1.2.0
*/ */
void array_list_remove(struct array_list* list, size_t index); void array_list_remove(struct array_list* list, size_t index);
/** /**
* @brief Gets an element from the array list. * @brief Gets an element from the array list.
*
* @param list
* @param index
* @return void*
* @since v1.2.0 * @since v1.2.0
*/ */
void* array_list_get(struct array_list* list, size_t index); void* array_list_get(struct array_list* list, size_t index);
/** /**
* @brief Frees the array list. * @brief Frees the array list.
*
* @param list
* @since v3.0.0 * @since v3.0.0
*/ */
void array_list_free(struct array_list* list); void array_list_free(struct array_list* list);

View File

@ -12,7 +12,7 @@
* @brief Append a character to a string, assuming string points to an array * @brief Append a character to a string, assuming string points to an array
* with enough space. * with enough space.
* *
* @p * @param string
* @param character * @param character
* @since v1.0.0 * @since v1.0.0
*/ */
@ -47,7 +47,9 @@ char character_to_lower(const char character);
/** /**
* @brief Check if the character is a digit ('0', '1', '2', '3', '4', '5', '6', '7, '8' or '9'). * @brief Check if the character is a digit ('0', '1', '2', '3', '4', '5', '6', '7, '8' or '9').
* *
* @return true if the character is a digit, false otherwise * @param character
* @return true
* @return false
* @since v1.0.0 * @since v1.0.0
*/ */
bool character_get_is_digit(const char character); bool character_get_is_digit(const char character);
@ -57,6 +59,7 @@ bool character_get_is_digit(const char character);
* Return 0 if the character is not a letter. * Return 0 if the character is not a letter.
* *
* @param character * @param character
* @return unsigned char
* @since v1.0.0 * @since v1.0.0
*/ */
unsigned char character_get_alphabet_position(const char character); unsigned char character_get_alphabet_position(const char character);

View File

@ -62,7 +62,7 @@ string_t convert_number_to_string(const long long integer) {
return string; return string;
} }
string_t 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 long base) {
if (number == 0) { if (number == 0) {
return "0"; return "0";
} }
@ -88,10 +88,10 @@ string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned
return result; return result;
} }
int convert_number_from_base_to_base_10(string_t number, unsigned int base) { unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long base) {
int length = string_get_length(number); size_t length = string_get_length(number);
int exponent = length - 1; int exponent = length - 1;
int result = 0; unsigned long result = 0;
int index = 0; int index = 0;
while (exponent >= 0) { while (exponent >= 0) {
int current_number = (int)(number[index] - '0'); int current_number = (int)(number[index] - '0');
@ -107,6 +107,6 @@ int convert_number_from_base_to_base_10(string_t number, unsigned int base) {
return result; return result;
} }
string_t convert_number_from_base_to_another(string_t number, int base_from, int base_target) { string_t convert_number_from_base_to_another(string_t number, unsigned long base_from, unsigned long base_target) {
return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target); return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target);
} }

View File

@ -15,6 +15,7 @@
* @brief Convert a character to a string. * @brief Convert a character to a string.
* *
* @param character * @param character
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t convert_character_to_string(const char character); string_t convert_character_to_string(const char character);
@ -23,6 +24,7 @@ string_t convert_character_to_string(const char character);
* @brief Convert a character to a digit. * @brief Convert a character to a digit.
* *
* @param character * @param character
* @return char
* @since v1.0.0 * @since v1.0.0
*/ */
char convert_character_to_digit(const char character); char convert_character_to_digit(const char character);
@ -31,6 +33,7 @@ char convert_character_to_digit(const char character);
* @brief Convert a digit to a character. * @brief Convert a digit to a character.
* *
* @param digit * @param digit
* @return char
* @since v1.0.0 * @since v1.0.0
*/ */
char convert_digit_to_character(const char digit); char convert_digit_to_character(const char digit);
@ -39,6 +42,7 @@ char convert_digit_to_character(const char digit);
* @brief Convert a string to a number. * @brief Convert a string to a number.
* *
* @param string * @param string
* @return long long
* @since v1.0.0 * @since v1.0.0
*/ */
long long convert_string_to_number(const string_t string); long long convert_string_to_number(const string_t string);
@ -47,6 +51,7 @@ long long convert_string_to_number(const string_t string);
* @brief Convert a number to a string. * @brief Convert a number to a string.
* *
* @param integer * @param integer
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t convert_number_to_string(const long long integer); string_t convert_number_to_string(const long long integer);
@ -56,18 +61,20 @@ string_t convert_number_to_string(const long long integer);
* *
* @param number * @param number
* @param base * @param base
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t 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 long base);
/** /**
* @brief Convert a number with a specific base to a number base 10. * @brief Convert a number with a specific base to a number base 10.
* *
* @param number * @param number
* @param base * @param base
* @return int
* @since v1.0.0 * @since v1.0.0
*/ */
int convert_number_from_base_to_base_10(string_t number, unsigned int base); unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long base);
/** /**
* @brief Convert a number with a specific base to a number of specific base. * @brief Convert a number with a specific base to a number of specific base.
@ -75,8 +82,9 @@ int convert_number_from_base_to_base_10(string_t number, unsigned int base);
* @param number * @param number
* @param base_from * @param base_from
* @param base_target * @param base_target
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t convert_number_from_base_to_another(string_t number, int base_from, int base_target); string_t convert_number_from_base_to_another(string_t number, unsigned long base_from, unsigned long base_target);
#endif #endif

View File

@ -18,9 +18,10 @@
* *
* @param path * @param path
* @param file_content * @param file_content
* @param file_size * @param file_size The size of the file that was read (mutated by the function).
* @retval -1 if the file does not exist or if there is an error. * @retval -1 if the file does not exist or if there is an error.
* @retval 0 for success. * @retval 0 for success.
* @return int
* @since v1.0.0 * @since v1.0.0
*/ */
int filesystem_read(string_t path, byte_t **file_content, off_t *file_size); int filesystem_read(string_t path, byte_t **file_content, off_t *file_size);
@ -33,6 +34,7 @@ int filesystem_read(string_t path, byte_t **file_content, off_t *file_size);
* @param file_size * @param file_size
* @retval -1 if there is an error. * @retval -1 if there is an error.
* @retval 0 for success. * @retval 0 for success.
* @return int
* @since v1.0.0 * @since v1.0.0
*/ */
int filesystem_write(string_t path, byte_t *file_content, off_t file_size); int filesystem_write(string_t path, byte_t *file_content, off_t file_size);
@ -41,8 +43,8 @@ int filesystem_write(string_t path, byte_t *file_content, off_t file_size);
* @brief Check if a path exists. * @brief Check if a path exists.
* *
* @param path * @param path
* @retval true if the path exists. * @return true
* @retval false if the path does not exist. * @return false
* @since v3.1.0 * @since v3.1.0
*/ */
bool filesystem_exists(string_t path); bool filesystem_exists(string_t path);
@ -54,6 +56,7 @@ bool filesystem_exists(string_t path);
* @return int * @return int
* @retval -1 if there is an error. * @retval -1 if there is an error.
* @retval 0 for success. * @retval 0 for success.
* @return int
* @since v3.1.0 * @since v3.1.0
*/ */
int filesystem_remove(string_t path); int filesystem_remove(string_t path);
@ -64,6 +67,7 @@ int filesystem_remove(string_t path);
* @param path * @param path
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
* @see https://www.iana.org/assignments/media-types/media-types.xhtml * @see https://www.iana.org/assignments/media-types/media-types.xhtml
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t filesystem_get_mimetype(string_t path); string_t filesystem_get_mimetype(string_t path);

View File

@ -35,22 +35,27 @@ struct hash_map_item {
/** /**
* @brief Hash function (using SipHash 1-3 algorithm). * @brief Hash function (using SipHash 1-3 algorithm).
* @param key
* @param capacity
* @see https://en.wikipedia.org/wiki/SipHash * @see https://en.wikipedia.org/wiki/SipHash
* @see https://github.com/veorq/SipHash * @see https://github.com/veorq/SipHash
*
* @param key
* @param capacity
* @return uint64_t
* @since v2.0.0 * @since v2.0.0
*/ */
uint64_t hash(string_t key, size_t capacity); uint64_t hash(string_t key, size_t capacity);
/** /**
* @brief Hash map initialization. * @brief Hash map initialization.
*
* @return struct hash_map*
* @since v2.0.0 * @since v2.0.0
*/ */
struct hash_map *hash_map_initialization(); struct hash_map *hash_map_initialization();
/** /**
* @brief Add an item to the hash map. * @brief Add an item to the hash map.
*
* @param hash_map * @param hash_map
* @param key * @param key
* @param data * @param data
@ -70,14 +75,18 @@ void hash_map_remove(struct hash_map *hash_map, string_t key);
* @brief Get an item from the hash map. * @brief Get an item from the hash map.
* @param hash_map * @param hash_map
* @param key * @param key
* @return void*
* @since v2.0.0 * @since v2.0.0
*/ */
void *hash_map_get(struct hash_map *hash_map, string_t key); void *hash_map_get(struct hash_map *hash_map, string_t key);
/** /**
* @brief Check if the hash map contains a key. * @brief Check if the hash map contains a key.
*
* @param hash_map * @param hash_map
* @param key * @param key
* @return true
* @return false
* @since v2.0.0 * @since v2.0.0
*/ */
bool hash_map_contains_key(struct hash_map *hash_map, string_t key); bool hash_map_contains_key(struct hash_map *hash_map, string_t key);
@ -86,12 +95,15 @@ bool hash_map_contains_key(struct hash_map *hash_map, string_t key);
* @brief Get the hash map keys. * @brief Get the hash map keys.
* *
* @param hash_map * @param hash_map
* @return string_t*
* @since v2.0.0 * @since v2.0.0
*/ */
string_t *hash_map_get_keys(struct hash_map *hash_map); string_t *hash_map_get_keys(struct hash_map *hash_map);
/** /**
* @brief Frees the hash map. * @brief Frees the hash map.
*
* @param hash_map
* @since v3.0.0 * @since v3.0.0
*/ */
void hash_map_free(struct hash_map *hash_map); void hash_map_free(struct hash_map *hash_map);

View File

@ -1,7 +1,7 @@
#include "linked_list.h" #include "linked_list.h"
struct linked_list *linked_list_initialization() { struct linked_list *linked_list_initialization() {
struct linked_list *list = malloc(sizeof(*list)); struct linked_list *list = malloc(sizeof(struct linked_list));
if (list == NULL) { if (list == NULL) {
perror("Error (linked_list_initialization)"); perror("Error (linked_list_initialization)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -17,7 +17,7 @@ struct linked_list_node *linked_list_add_in_head(struct linked_list *list, void
perror("Error (linked_list_add_in_head)"); perror("Error (linked_list_add_in_head)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
struct linked_list_node *node_new = malloc(sizeof(*node_new)); struct linked_list_node *node_new = malloc(sizeof(struct linked_list_node));
if (node_new == NULL) { if (node_new == NULL) {
perror("Error (linked_list_add_in_head)"); perror("Error (linked_list_add_in_head)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -52,7 +52,7 @@ struct linked_list_node *linked_list_add_after_last(struct linked_list *list, vo
if (list->head == NULL) { if (list->head == NULL) {
return linked_list_add_in_head(list, new_data); return linked_list_add_in_head(list, new_data);
} }
struct linked_list_node *node_new = malloc(sizeof(*node_new)); struct linked_list_node *node_new = malloc(sizeof(struct linked_list_node));
if (node_new == NULL) { if (node_new == NULL) {
perror("Error (linked_list_add_after_last)"); perror("Error (linked_list_add_after_last)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@ -14,7 +14,6 @@
*/ */
struct linked_list { struct linked_list {
struct linked_list_node *head; struct linked_list_node *head;
size_t length; size_t length;
}; };
@ -29,42 +28,61 @@ struct linked_list_node {
/** /**
* @brief Linked list initialization. * @brief Linked list initialization.
*
* @return struct linked_list*
* @since v1.0.0 * @since v1.0.0
*/ */
struct linked_list *linked_list_initialization(); struct linked_list *linked_list_initialization();
/** /**
* @brief Add a new node in the head of the linked list. * @brief Add a new node in the head of the linked list.
*
* @param list
* @param new_value
* @return struct linked_list_node*
* @since v1.0.0 * @since v1.0.0
*/ */
struct linked_list_node *linked_list_add_in_head(struct linked_list *list, void *new_value); struct linked_list_node *linked_list_add_in_head(struct linked_list *list, void *new_value);
/** /**
* @brief Delete node in the head of the linked list. * @brief Delete node in the head of the linked list.
*
* @param list
* @since v1.0.0 * @since v1.0.0
*/ */
void linked_list_delete_in_head(struct linked_list *list); void linked_list_delete_in_head(struct linked_list *list);
/** /**
* @brief Add a new node in the tail of the linked list. * @brief Add a new node in the tail of the linked list.
*
* @param list
* @param new_data
* @return struct linked_list_node*
* @since v1.0.0 * @since v1.0.0
*/ */
struct linked_list_node *linked_list_add_after_last(struct linked_list *list, void *new_data); struct linked_list_node *linked_list_add_after_last(struct linked_list *list, void *new_data);
/** /**
* @brief Reverse the linked list by creating a new one. * @brief Reverse the linked list by creating a new one.
*
* @param list
* @return struct linked_list*
* @since v1.0.0 * @since v1.0.0
*/ */
struct linked_list *linked_list_reverse(struct linked_list *list); struct linked_list *linked_list_reverse(struct linked_list *list);
/** /**
* @brief Reverse the linked list by mutating it. * @brief Reverse the linked list by mutating it.
*
* @param list
* @since v1.0.0 * @since v1.0.0
*/ */
void linked_list_reverse_mutate(struct linked_list *list); void linked_list_reverse_mutate(struct linked_list *list);
/** /**
* @brief Frees the linked list. * @brief Frees the linked list.
*
* @param list
* @since v3.0.0 * @since v3.0.0
*/ */
void linked_list_free(struct linked_list *list); void linked_list_free(struct linked_list *list);

View File

@ -13,6 +13,8 @@
* *
* @param number1 * @param number1
* @param number2 * @param number2
* @return true
* @return false
* @since v1.0.0 * @since v1.0.0
*/ */
bool mathematics_equals(const float number1, const float number2); bool mathematics_equals(const float number1, const float number2);
@ -21,6 +23,7 @@ bool mathematics_equals(const float number1, const float number2);
* @brief Get the absolute value of a number. * @brief Get the absolute value of a number.
* *
* @param number * @param number
* @return unsigned long long
* @since v1.0.0 * @since v1.0.0
*/ */
unsigned long long mathematics_absolute_value(const long long number); unsigned long long mathematics_absolute_value(const long long number);
@ -30,15 +33,17 @@ unsigned long long mathematics_absolute_value(const long long number);
* *
* @param base * @param base
* @param exponent * @param exponent
* @return unsigned long long
* @since v1.0.0 * @since v1.0.0
*/ */
unsigned long long mathematics_pow(unsigned long long base, unsigned long long exponent); unsigned long long mathematics_pow(unsigned long long base, unsigned long long exponent);
/** /**
* @brief Calculates the nth root of a number using Heron's method. * @brief Calculates the nth root of a number.
* *
* @param number * @param number
* @param nth_root * @param nth_root
* @return float
* @since v1.0.0 * @since v1.0.0
*/ */
float mathematics_root(float number, unsigned int nth_root); float mathematics_root(float number, unsigned int nth_root);
@ -47,6 +52,7 @@ float mathematics_root(float number, unsigned int nth_root);
* @brief Calculates the square root of a number using Heron's method. * @brief Calculates the square root of a number using Heron's method.
* *
* @param number * @param number
* @return float
* @since v1.0.0 * @since v1.0.0
*/ */
float mathematics_square_root(float number); float mathematics_square_root(float number);
@ -55,6 +61,7 @@ float mathematics_square_root(float number);
* @brief Calculates the factorial of a number. * @brief Calculates the factorial of a number.
* *
* @param number * @param number
* @return unsigned long long
* @since v1.0.0 * @since v1.0.0
*/ */
unsigned long long mathematics_factorial(unsigned long long number); unsigned long long mathematics_factorial(unsigned long long number);

View File

@ -1,7 +1,7 @@
#include "queue.h" #include "queue.h"
struct queue *queue_initialization() { struct queue *queue_initialization() {
struct queue *queue = malloc(sizeof(*queue)); struct queue *queue = malloc(sizeof(struct queue));
if (queue == NULL) { if (queue == NULL) {
perror("Error (queue_initialization)"); perror("Error (queue_initialization)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -17,7 +17,7 @@ void queue_push(struct queue *queue, void *data) {
perror("Error (queue_push)"); perror("Error (queue_push)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
struct queue_node *node_new = malloc(sizeof(*node_new)); struct queue_node *node_new = malloc(sizeof(struct queue_node));
if (node_new == NULL) { if (node_new == NULL) {
perror("Error (queue_push)"); perror("Error (queue_push)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@ -27,24 +27,34 @@ struct queue_node {
/** /**
* @brief Queue initialization. * @brief Queue initialization.
*
* @return struct queue*
* @since v1.0.0 * @since v1.0.0
*/ */
struct queue *queue_initialization(); struct queue *queue_initialization();
/** /**
* @brief Push data to queue. * @brief Push data to queue.
*
* @param queue
* @param data
* @since v1.0.0 * @since v1.0.0
*/ */
void queue_push(struct queue *queue, void *data); void queue_push(struct queue *queue, void *data);
/** /**
* @brief Pop data from queue. * @brief Pop data from queue.
*
* @param queue
* @return void*
* @since v1.0.0 * @since v1.0.0
*/ */
void *queue_pop(struct queue *queue); void *queue_pop(struct queue *queue);
/** /**
* @brief Frees the queue. * @brief Frees the queue.
*
* @param queue
* @since v3.0.0 * @since v3.0.0
*/ */
void queue_free(struct queue *queue); void queue_free(struct queue *queue);

View File

@ -1,7 +1,7 @@
#include "stack.h" #include "stack.h"
struct stack *stack_initialization() { struct stack *stack_initialization() {
struct stack *stack = malloc(sizeof(*stack)); struct stack *stack = malloc(sizeof(struct stack));
if (stack == NULL) { if (stack == NULL) {
perror("Error (stack_initialization)"); perror("Error (stack_initialization)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -17,7 +17,7 @@ void stack_push(struct stack *stack, void *data) {
perror("Error (stack_push)"); perror("Error (stack_push)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
struct stack_node *node_new = malloc(sizeof(*node_new)); struct stack_node *node_new = malloc(sizeof(struct stack_node));
if (data == NULL) { if (data == NULL) {
perror("Error (stack_push)"); perror("Error (stack_push)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@ -27,24 +27,34 @@ struct stack_node {
/** /**
* @brief Stack initialization. * @brief Stack initialization.
*
* @return struct stack*
* @since v1.0.0 * @since v1.0.0
*/ */
struct stack *stack_initialization(); struct stack *stack_initialization();
/** /**
* @brief Push data to stack. * @brief Push data to stack.
*
* @param stack
* @param data
* @since v1.0.0 * @since v1.0.0
*/ */
void stack_push(struct stack *stack, void *data); void stack_push(struct stack *stack, void *data);
/** /**
* @brief Pop data from stack. * @brief Pop data from stack.
*
* @param stack
* @return void*
* @since v1.0.0 * @since v1.0.0
*/ */
void *stack_pop(struct stack *stack); void *stack_pop(struct stack *stack);
/** /**
* @brief Frees the stack. * @brief Frees the stack.
*
* @param stack
* @since v3.0.0 * @since v3.0.0
*/ */
void stack_free(struct stack *stack); void stack_free(struct stack *stack);

View File

@ -37,6 +37,20 @@ void string_replace(string_t string, char search, char replace) {
string[string_length] = '\0'; string[string_length] = '\0';
} }
void string_remove_character(string_t string, char search) {
size_t string_length = string_get_length(string);
for (size_t index = 0; index < string_length; index++) {
if (string[index] == search) {
for (size_t index_string = index; index_string < string_length; index_string++) {
string[index_string] = string[index_string + 1];
}
string_length--;
index--;
}
}
string[string_length] = '\0';
}
void string_trim_start(string_t string, char character) { void string_trim_start(string_t string, char character) {
size_t string_length = string_get_length(string); size_t string_length = string_get_length(string);
size_t index_space = 0; size_t index_space = 0;
@ -370,3 +384,26 @@ bool string_ends_with(const string_t string, const string_t prefix) {
} }
return ends_with; return ends_with;
} }
size_t string_position_of(const string_t string, const char character) {
size_t position_found = 0;
size_t string_length = string_get_length(string);
for (size_t index = 0; index < string_length && position_found == 0; index++) {
if (string[index] == character) {
position_found = index + 1;
}
}
return position_found;
}
size_t string_last_position_of(const string_t string, const char character) {
size_t position_found = 0;
size_t string_length = string_get_length(string);
while (string_length > 0 && position_found == 0) {
if (string[string_length - 1] == character) {
position_found = string_length;
}
string_length--;
}
return position_found;
}

View File

@ -15,6 +15,7 @@
* @brief Return the length of a string (excluding '\0'). * @brief Return the length of a string (excluding '\0').
* *
* @param string * @param string
* @return size_t
* @since v1.0.0 * @since v1.0.0
*/ */
size_t string_get_length(const string_t string); size_t string_get_length(const string_t string);
@ -51,6 +52,17 @@ void string_to_lowercase(string_t string);
*/ */
void string_replace(string_t string, char search, char replace); void string_replace(string_t string, char search, char replace);
/**
* @brief Removes all the occurrences of a character in a string.
*
* NOTE: Mutates the string.
*
* @param string
* @param search A character search value.
* @since v4.1.0
*/
void string_remove_character(string_t string, char search);
/** /**
* @brief Removes all `character` from the start of a string. * @brief Removes all `character` from the start of a string.
* *
@ -85,6 +97,7 @@ void string_trim(string_t string, char character);
* @brief Return the copy of a string. * @brief Return the copy of a string.
* *
* @param string * @param string
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t string_copy(const string_t string); string_t string_copy(const string_t string);
@ -104,6 +117,7 @@ void string_capitalize(string_t string);
* *
* @param string * @param string
* @param character * @param character
* @return size_t
* @since v1.0.0 * @since v1.0.0
*/ */
size_t string_total_occurrences_of_character(string_t string, char character); size_t string_total_occurrences_of_character(string_t string, char character);
@ -123,16 +137,18 @@ void string_reverse(const string_t string);
* *
* @param string1 * @param string1
* @param string2 * @param string2
* @return true if the strings are equals, false otherwise. * @return true if the strings are equals.
* @return false if the strings are not equals.
* @since v1.0.0 * @since v1.0.0
*/ */
bool string_equals(const string_t string1, const string_t string2); bool string_equals(const string_t string1, const string_t string2);
/** /**
* @brief Check if the string is a integer. * @brief Check if the string is an integer.
* *
* @param string * @param string
* @return true if the string is a integer, false otherwise. * @return true if the string is an integer.
* @return false if the string is not an integer.
* @since v1.0.0 * @since v1.0.0
*/ */
bool string_get_is_integer(const string_t string); bool string_get_is_integer(const string_t string);
@ -143,6 +159,7 @@ bool string_get_is_integer(const string_t string);
* @param string * @param string
* @param separator * @param separator
* @param result_size * @param result_size
* @return string_t*
* @since v1.0.0 * @since v1.0.0
*/ */
string_t* string_split(const string_t string, char separator, size_t* result_size); string_t* string_split(const string_t string, char separator, size_t* result_size);
@ -153,6 +170,7 @@ string_t* string_split(const string_t string, char separator, size_t* result_siz
* @param array * @param array
* @param separator * @param separator
* @param array_length * @param array_length
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t string_join(string_t* array, const char separator, size_t array_length); string_t string_join(string_t* array, const char separator, size_t array_length);
@ -172,7 +190,8 @@ void string_concatenate(string_t* destination, string_t source);
* @brief Check if a string contains only unique characters. * @brief Check if a string contains only unique characters.
* *
* @param string * @param string
* @return true if string contains only unique characters, false otherwise. * @return true if string contains only unique characters.
* @return false if string contains duplicate characters.
* @since v1.0.0 * @since v1.0.0
*/ */
bool string_get_has_unique_characters(const string_t string); bool string_get_has_unique_characters(const string_t string);
@ -183,6 +202,7 @@ bool string_get_has_unique_characters(const string_t string);
* @param string * @param string
* @param index_start * @param index_start
* @param index_end * @param index_end
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t string_substring(const string_t string, size_t index_start, size_t index_end); string_t string_substring(const string_t string, size_t index_start, size_t index_end);
@ -192,7 +212,8 @@ string_t string_substring(const string_t string, size_t index_start, size_t inde
* *
* @param string * @param string
* @param substring * @param substring
* @return true if the string contains the substring, false otherwise. * @return true if the string contains the substring.
* @return false if the string does not contain the substring.
* @since v1.0.0 * @since v1.0.0
*/ */
bool string_get_is_substring(const string_t string, const string_t substring); bool string_get_is_substring(const string_t string, const string_t substring);
@ -202,11 +223,12 @@ bool string_get_is_substring(const string_t string, const string_t substring);
* *
* @param number * @param number
* @param separator * @param separator
* @since v1.0.0 * @return string_t
* @code * @code
* string_get_formatted_number(1000, " ") // "1 000" * string_get_formatted_number(1000, " ") // "1 000"
* string_get_formatted_number(1000, ",") // "1,000" * string_get_formatted_number(1000, ",") // "1,000"
* @endcode * @endcode
* @since v1.0.0
*/ */
string_t string_get_formatted_number(const long long number, string_t separator); string_t string_get_formatted_number(const long long number, string_t separator);
@ -215,6 +237,7 @@ string_t string_get_formatted_number(const long long number, string_t separator)
* *
* @param string * @param string
* @param character * @param character
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t string_get_last_occurence_of_character(const string_t string, char character); string_t string_get_last_occurence_of_character(const string_t string, char character);
@ -224,7 +247,8 @@ string_t string_get_last_occurence_of_character(const string_t string, char char
* *
* @param string * @param string
* @param prefix * @param prefix
* @return true if the string starts with the substring, false otherwise. * @return true if the string starts with the substring.
* @return false if the string does not start with the substring.
* @since v1.0.0 * @since v1.0.0
*/ */
bool string_starts_with(const string_t string, const string_t prefix); bool string_starts_with(const string_t string, const string_t prefix);
@ -234,9 +258,32 @@ bool string_starts_with(const string_t string, const string_t prefix);
* *
* @param string * @param string
* @param prefix * @param prefix
* @return true if the string ends with the substring, false otherwise. * @return true if the string ends with the substring.
* @return false if the string does not end with the substring.
* @since v1.0.0 * @since v1.0.0
*/ */
bool string_ends_with(const string_t string, const string_t prefix); bool string_ends_with(const string_t string, const string_t prefix);
/**
* @brief Returns the position (index + 1) within the string of the first occurrence of the specified substring (0 if not found).
*
* @param string
* @param substring
* @return size_t
* @example string_position_of("hello world", 'e') // 2
* @since v4.2.0
*/
size_t string_position_of(const string_t string, const char character);
/**
* @brief Returns the position (index + 1) within the string of the last occurrence of the specified substring (0 if not found).
*
* @param string
* @param character
* @return size_t
* @example string_last_position_of("hello world", 'o') // 8
* @since v4.2.0
*/
size_t string_last_position_of(const string_t string, const char character);
#endif #endif

View File

@ -24,7 +24,7 @@ string_t terminal_input() {
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) { void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) {
printf("["); printf("[");
for (size_t index = 0; index < array_size; index++) { for (size_t index = 0; index < array_size; index++) {
void* element = (char*)array + index * element_size; void* element = (string_t)array + index * element_size;
print_element(element); print_element(element);
bool is_last = index == array_size - 1; bool is_last = index == array_size - 1;
if (!is_last) { if (!is_last) {
@ -47,11 +47,11 @@ void terminal_print_unsigned_long(void* value) {
} }
void terminal_print_char(void* value) { void terminal_print_char(void* value) {
printf("%c", *(char*)value); printf("%c", *(string_t)value);
} }
void terminal_print_string(void* value) { void terminal_print_string(void* value) {
printf("%s", (char*)value); printf("%s", (string_t)value);
} }
void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) { void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) {
@ -63,7 +63,7 @@ void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) {
struct stack_node* node_current = stack->first; struct stack_node* node_current = stack->first;
while (node_current != NULL) { while (node_current != NULL) {
printf("|\t"); printf("|\t");
void* element = (char*)node_current->data; void* element = node_current->data;
print_element(&element); print_element(&element);
node_current = node_current->next; node_current = node_current->next;
printf("\t|\n"); printf("\t|\n");
@ -79,7 +79,7 @@ void terminal_print_queue(struct queue* queue, void (*print_element)(void*)) {
struct queue_node* node_current = queue->first; struct queue_node* node_current = queue->first;
while (node_current != NULL) { while (node_current != NULL) {
printf("|\t"); printf("|\t");
void* element = (char*)node_current->data; void* element = node_current->data;
print_element(&element); print_element(&element);
node_current = node_current->next; node_current = node_current->next;
printf("\t|\n"); printf("\t|\n");
@ -94,7 +94,7 @@ void terminal_print_linked_list(struct linked_list* linked_list, void (*print_el
} }
struct linked_list_node* node_current = linked_list->head; struct linked_list_node* node_current = linked_list->head;
while (node_current != NULL) { while (node_current != NULL) {
void* element = (char*)node_current->data; void* element = (string_t)node_current->data;
node_current = node_current->next; node_current = node_current->next;
print_element(&element); print_element(&element);
printf(" -> "); printf(" -> ");

View File

@ -17,6 +17,8 @@
/** /**
* @brief Read a line from stdin. * @brief Read a line from stdin.
*
* @return string_t
* @since v1.0.0 * @since v1.0.0
*/ */
string_t terminal_input(); string_t terminal_input();
@ -111,7 +113,7 @@ void terminal_print_hash_map(struct hash_map* hash_map, void (*print_element)(vo
/** /**
* @brief Print an array list. * @brief Print an array list.
* *
* @param array_list * @param list
* @param print_element * @param print_element
* @since v3.0.0 * @since v3.0.0
*/ */

View File

@ -3,7 +3,7 @@
#include "libcproject.h" #include "libcproject.h"
int main(int argc, char** argv) { int main(int argc, string_t* argv) {
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: %s <version>\n", argv[0]); fprintf(stderr, "Usage: %s <version>\n", argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
@ -16,6 +16,7 @@ int main(int argc, char** argv) {
int result = filesystem_write("./version.h", (byte_t*)content, string_get_length(content)); int result = filesystem_write("./version.h", (byte_t*)content, string_get_length(content));
if (result == -1) { if (result == -1) {
fprintf(stderr, "Error: Could not write to file.\n"); fprintf(stderr, "Error: Could not write to file.\n");
perror("Error (set_version)");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("Success: Version set to %s.\n", argv[1]); printf("Success: Version set to %s.\n", argv[1]);

View File

@ -34,4 +34,15 @@ void array_list_test() {
assert(array_list_get(list, 100) == (void *)95); assert(array_list_get(list, 100) == (void *)95);
array_list_free(list); array_list_free(list);
list = array_list_initialization();
array_list_add(list, (void *)'a');
array_list_add(list, (void *)'b');
array_list_add(list, (void *)'c');
array_list_remove(list, 1);
assert(array_list_get(list, 0) == (void *)'a');
assert(array_list_get(list, 1) == (void *)'c');
assert(list->size == 2);
array_list_free(list);
} }

View File

@ -10,7 +10,7 @@ void convert_test() {
} }
void convert_character_to_string_test() { void convert_character_to_string_test() {
char* result = convert_character_to_string('a'); string_t result = convert_character_to_string('a');
assert(assert_string_equal(result, "a")); assert(assert_string_equal(result, "a"));
free(result); free(result);
@ -77,7 +77,7 @@ void convert_string_to_number_test() {
} }
void convert_number_to_string_test() { void convert_number_to_string_test() {
char* result = convert_number_to_string(0); string_t result = convert_number_to_string(0);
assert(assert_string_equal(result, "0")); assert(assert_string_equal(result, "0"));
free(result); free(result);
@ -143,7 +143,7 @@ void convert_number_to_string_test() {
} }
void convert_number_from_base_to_another_test() { void convert_number_from_base_to_another_test() {
char* result = convert_number_from_base_to_another("15", 10, 16); string_t result = convert_number_from_base_to_another("15", 10, 16);
assert(assert_string_equal(result, "F")); assert(assert_string_equal(result, "F"));
free(result); free(result);

View File

@ -5,6 +5,7 @@ void string_test() {
string_to_uppercase_test(); string_to_uppercase_test();
string_to_lowercase_test(); string_to_lowercase_test();
string_replace_test(); string_replace_test();
string_remove_character_test();
string_trim_start_test(); string_trim_start_test();
string_trim_end_test(); string_trim_end_test();
string_trim_test(); string_trim_test();
@ -24,6 +25,8 @@ void string_test() {
string_get_last_occurence_of_character_test(); string_get_last_occurence_of_character_test();
string_starts_with_test(); string_starts_with_test();
string_ends_with_test(); string_ends_with_test();
string_position_of_test();
string_last_position_of_test();
} }
void string_get_length_test() { void string_get_length_test() {
@ -54,6 +57,13 @@ void string_replace_test() {
free(string); free(string);
} }
void string_remove_character_test() {
string_t string = string_copy("hello world");
string_remove_character(string, 'l');
assert(assert_string_equal(string, "heo word"));
free(string);
}
void string_trim_start_test() { void string_trim_start_test() {
string_t string = string_copy(" hello world "); string_t string = string_copy(" hello world ");
string_trim_start(string, ' '); string_trim_start(string, ' ');
@ -195,7 +205,7 @@ void string_get_is_substring_test() {
} }
void string_get_formatted_number_test() { void string_get_formatted_number_test() {
char* result = string_get_formatted_number(1000, " "); string_t result = string_get_formatted_number(1000, " ");
assert(assert_string_equal(result, "1 000")); assert(assert_string_equal(result, "1 000"));
free(result); free(result);
@ -227,7 +237,7 @@ void string_get_formatted_number_test() {
void string_get_last_occurence_of_character_test() { void string_get_last_occurence_of_character_test() {
string_t string = "abcdef"; string_t string = "abcdef";
char* result = string_get_last_occurence_of_character(string, 'a'); string_t result = string_get_last_occurence_of_character(string, 'a');
assert(assert_string_equal(result, "abcdef")); assert(assert_string_equal(result, "abcdef"));
free(result); free(result);
@ -269,3 +279,27 @@ void string_ends_with_test() {
assert(!string_ends_with("abcdef", "bcd")); assert(!string_ends_with("abcdef", "bcd"));
assert(!string_ends_with("abcdef", "abcdefg")); assert(!string_ends_with("abcdef", "abcdefg"));
} }
void string_position_of_test() {
assert(string_position_of("hello world", 'e') == 2);
assert(string_position_of("hello world", 'o') == 5);
assert(string_position_of("abcdef", 'a') == 1);
assert(string_position_of("abcdef", 'b') == 2);
assert(string_position_of("abcdef", 'c') == 3);
assert(string_position_of("abcdef", 'd') == 4);
assert(string_position_of("abcdef", 'e') == 5);
assert(string_position_of("abcdef", 'f') == 6);
assert(string_position_of("abcdef", 'g') == 0);
}
void string_last_position_of_test() {
assert(string_last_position_of("hello world", 'e') == 2);
assert(string_last_position_of("hello world", 'o') == 8);
assert(string_last_position_of("abcdef", 'a') == 1);
assert(string_last_position_of("abcdef", 'b') == 2);
assert(string_last_position_of("abcdef", 'c') == 3);
assert(string_last_position_of("abcdef", 'd') == 4);
assert(string_last_position_of("abcdef", 'e') == 5);
assert(string_last_position_of("abcdef", 'f') == 6);
assert(string_last_position_of("abcdef", 'g') == 0);
}

View File

@ -18,6 +18,8 @@ void string_to_lowercase_test();
void string_replace_test(); void string_replace_test();
void string_remove_character_test();
void string_trim_start_test(); void string_trim_start_test();
void string_trim_end_test(); void string_trim_end_test();
@ -56,4 +58,8 @@ void string_starts_with_test();
void string_ends_with_test(); void string_ends_with_test();
void string_position_of_test();
void string_last_position_of_test();
#endif #endif

View File

@ -1,4 +1,4 @@
#ifndef __LIBCPROJECT_VERSION__ #ifndef __LIBCPROJECT_VERSION__
#define __LIBCPROJECT_VERSION__ "4.0.0" #define __LIBCPROJECT_VERSION__ "4.2.1"
#endif #endif