Compare commits

..

No commits in common. "8714361e85d05d3d5d796255c5744607ff7d5753" and "b5fd577504671030c1278934a9a7db6c6d4af9d8" have entirely different histories.

4 changed files with 1 additions and 133 deletions

View file

@ -1,41 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: String.h
* Description:
* This file contains the String structure and the functions for modifying it.
* It includes functions to append, Insert at index, insert before character,
* insert before string, insert after character, insert after string, replace,
* copy, pop, remove, remove range, clear, check if contains string, check if
* empty.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#ifndef FLEDASTY_STRING
#define FLEDASTY_STRING
#include <stddef.h>
#include <stdbool.h>
#include "../Utils/Error.h"
typedef struct {
size_t size, capacity;
char *character_string;
} FledastyString;
FledastyError fledasty_string_free(FledastyString *current_string);
#endif

View file

@ -1,43 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: String.c
* Description:
* This file contains the functions for modifying the String. It includes
* functions to append, Insert at index, insert before character,
* insert before string, insert after character, insert after string, replace,
* copy, pop, remove, remove range, clear, check if contains string, check if
* empty.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#include "../../Include/Fledasty/Strings/String.h"
#include <Hallocy/Core/Allocator.h>
#include <Hallocy/Core/Memory.h>
#include <Hallocy/Utils/Error.h>
FledastyError fledasty_string_free(FledastyString *current_string) {
if (current_string == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
if (hallocy_free(current_string->character_string) != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
current_string->character_string = NULL;
return FLEDASTY_ERROR_NONE;
}

View file

@ -24,6 +24,7 @@
* -----------------------------------------------------------------------------
*/
#include "../../Include/Fledasty/Strings/UTF8String.h"
#include "Fledasty/Utils/Error.h"
#include <Hallocy/Core/Allocator.h>
#include <Hallocy/Core/Memory.h>
@ -56,10 +57,6 @@ FledastyError fledasty_utf8_string_append(FledastyUtf8String *current_string, un
if (current_string->capacity <= current_string->size + character_string_size) {
current_string->capacity += (current_string->capacity > character_string_size) ? current_string->capacity : character_string_size + 1;
current_string->character_string = (unsigned char*)hallocy_realloc(current_string->character_string, current_string->capacity * sizeof(unsigned char));
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
}
hallocy_copy_memory(current_string->character_string + current_string->size, character_string, character_string_size);
@ -86,10 +83,6 @@ FledastyError fledasty_utf8_string_insert_at_index(FledastyUtf8String *current_s
if (current_string->capacity <= current_string->size + character_string_size) {
current_string->capacity += (current_string->capacity > character_string_size) ? current_string->capacity : character_string_size;
current_string->character_string = (unsigned char*)hallocy_realloc(current_string->character_string, current_string->capacity * sizeof(unsigned char));
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
}
hallocy_move_memory(current_string->character_string + (index + character_string_size), current_string->character_string + index, current_string->size - index);
@ -115,10 +108,6 @@ FledastyError fledasty_utf8_string_insert_before_string(FledastyUtf8String *curr
if (current_string->capacity <= current_string->size + character_string_size) {
current_string->capacity += (current_string->capacity > character_string_size) ? current_string->capacity : character_string_size + 1;
current_string->character_string = (unsigned char*)hallocy_realloc(current_string->character_string, current_string->capacity * sizeof(unsigned char));
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
}
hallocy_move_memory(current_string->character_string + (index + character_string_size), current_string->character_string + index, current_string->size - index);
@ -149,10 +138,6 @@ FledastyError fledasty_utf8_string_insert_after_string(FledastyUtf8String *curre
if (current_string->capacity <= current_string->size + character_string_size) {
current_string->capacity += (current_string->capacity > character_string_size) ? current_string->capacity : character_string_size + 1;
current_string->character_string = (unsigned char*)hallocy_realloc(current_string->character_string, current_string->capacity * sizeof(unsigned char));
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
}
index += after_character_string_size;
@ -246,10 +231,6 @@ FledastyError fledasty_utf8_string_replace_string(FledastyUtf8String *current_st
if (current_string->capacity <= new_size) {
current_string->capacity += (current_string->capacity > character_string_size) ? current_string->capacity : character_string_size;
current_string->character_string = (unsigned char*)hallocy_realloc(current_string->character_string, current_string->capacity * sizeof(unsigned char));
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
}
hallocy_move_memory(current_string->character_string + index + character_string_size, current_string->character_string + index + replace_character_string_size, current_string->size - (index + replace_character_string_size));
@ -285,10 +266,6 @@ FledastyError fledasty_utf8_string_shrink_to_fit(FledastyUtf8String *current_str
current_string->capacity = current_string->size + 1;
current_string->character_string = (unsigned char*)hallocy_malloc(current_string->capacity);
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
hallocy_copy_memory(current_string->character_string, previous_string, current_string->size);
current_string->character_string[current_string->size] = '\0';
@ -329,10 +306,6 @@ FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const si
if (utf8_string.capacity <= string_index) {
utf8_string.capacity += (utf8_string.capacity > FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE) ? utf8_string.capacity : FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE;
utf8_string.character_string = (unsigned char*)hallocy_realloc(utf8_string.character_string, utf8_string.capacity);
if (utf8_string.character_string == NULL) {
return utf8_string;
}
}
utf8_string.character_string[string_index] = unicode[index];
@ -341,10 +314,6 @@ FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const si
if (utf8_string.capacity <= string_index + 2) {
utf8_string.capacity += (utf8_string.capacity > FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE) ? utf8_string.capacity : FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE;
utf8_string.character_string = (unsigned char*)hallocy_realloc(utf8_string.character_string, utf8_string.capacity);
if (utf8_string.character_string == NULL) {
return utf8_string;
}
}
utf8_string.character_string[string_index] = 0xC0 | ((unicode[index] >> 6) & 0x07);
@ -354,10 +323,6 @@ FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const si
if (utf8_string.capacity <= string_index + 3) {
utf8_string.capacity += (utf8_string.capacity > FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE) ? utf8_string.capacity : FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE;
utf8_string.character_string = (unsigned char*)hallocy_realloc(utf8_string.character_string, utf8_string.capacity);
if (utf8_string.character_string == NULL) {
return utf8_string;
}
}
utf8_string.character_string[string_index] = 0xE0 | ((unicode[index] >> 12) & 0x07);
@ -368,10 +333,6 @@ FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const si
if (utf8_string.capacity <= string_index + 4) {
utf8_string.capacity += (utf8_string.capacity > FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE) ? utf8_string.capacity : FLEDASTY_STRING_DEFAULT_ALLOCATION_SIZE;
utf8_string.character_string = (unsigned char*)hallocy_realloc(utf8_string.character_string, utf8_string.capacity);
if (utf8_string.character_string == NULL) {
return utf8_string;
}
}
utf8_string.character_string[string_index] = 0xF0 | ((unicode[index] >> 18) & 0x07);
@ -400,10 +361,6 @@ uint32_t *fledasty_utf8_string_decode(const FledastyUtf8String *current_string,
(*unicode_string_size) = 0;
size_t index = 0;
uint32_t *unicode_string = (uint32_t*)hallocy_malloc(current_string->size * sizeof(uint32_t));
if (unicode_string == NULL) {
return NULL;
}
while (index < current_string->size) {
if ((current_string->character_string[index] & 0xF0) == 0xF0) {
unicode_string[*unicode_string_size] = ((current_string->character_string[index] & 0x07) << 18) | ((current_string->character_string[index + 1] & 0x3F) << 12) | ((current_string->character_string[index + 2] & 0x3F) << 6) | (current_string->character_string[index + 3] & 0x3F);

View file

@ -28,7 +28,6 @@
#include <Fledasty/Core/DoublyLinkedList.h>
#include <Fledasty/Core/HashTable.h>
#include <Fledasty/Strings/UTF8String.h>
#include <Fledasty/Strings/String.h>
#include <Fledasty/Algorithms/Hashing.h>
static inline bool compare_integers(const int first_value, const int second_value) { return first_value == second_value; }
@ -282,10 +281,6 @@ int main() {
fledasty_utf8_string_free(&encoded_string);
fledasty_utf8_string_free(&test_utf8_string);
FledastyString normal_test_string = { 0, 0, NULL };
fledasty_string_free(&normal_test_string);
printf("Done\n");
return 0;
}