feat(string): added simple string struct and free function
This commit is contained in:
parent
b5fd577504
commit
f27562c23e
3 changed files with 89 additions and 0 deletions
41
Include/Fledasty/Strings/String.h
Normal file
41
Include/Fledasty/Strings/String.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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
|
||||
43
Src/Strings/String.c
Normal file
43
Src/Strings/String.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
#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; }
|
||||
|
|
@ -281,6 +282,10 @@ 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;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue