2021-09-28 23:58:00 +02:00
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "character.h"
|
|
|
|
|
|
|
|
char* string_to_upper(const char* string) {
|
|
|
|
size_t string_length = strlen(string);
|
|
|
|
char* result = malloc(sizeof(char) * (string_length + 1));
|
|
|
|
for (size_t index = 0; index < string_length; index++) {
|
|
|
|
character_append(result, character_to_upper(string[index]));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* string_reverse(const char* string) {
|
|
|
|
size_t string_length = strlen(string);
|
|
|
|
char* result = malloc(sizeof(char) * (string_length + 1));
|
2021-10-13 21:43:45 +02:00
|
|
|
for (int index = string_length - 1; index != -1; index--) {
|
2021-09-28 23:58:00 +02:00
|
|
|
character_append(result, string[index]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool string_is_palindrome(const char* string) {
|
|
|
|
char* string_reversed = string_reverse(string);
|
|
|
|
bool is_palindrome = strcmp(string_reversed, string) == 0;
|
|
|
|
free(string_reversed);
|
|
|
|
return is_palindrome;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:10:40 +02:00
|
|
|
char* string_replace(const char* string, char search, char replace) {
|
2021-09-28 23:58:00 +02:00
|
|
|
size_t string_length = strlen(string);
|
|
|
|
char* result = malloc(sizeof(char) * (string_length + 1));
|
|
|
|
for (size_t index = 0; index < string_length; index++) {
|
2021-09-29 00:10:40 +02:00
|
|
|
bool is_search_value = search == string[index];
|
2021-09-28 23:58:00 +02:00
|
|
|
if (is_search_value) {
|
2021-09-29 00:10:40 +02:00
|
|
|
character_append(result, replace);
|
2021-09-28 23:58:00 +02:00
|
|
|
} else {
|
|
|
|
character_append(result, string[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|