feat(utf-8): implemented has string function
This commit is contained in:
parent
062d10805f
commit
0e67969ff1
3 changed files with 22 additions and 0 deletions
|
|
@ -42,6 +42,7 @@ FledastyError fledasty_utf8_string_insert_before_string(FledastyUtf8String *curr
|
||||||
FledastyError fledasty_utf8_string_insert_after_string(FledastyUtf8String *current_string, unsigned char *after_character_string, size_t after_character_string_length, unsigned char *character_string, size_t character_string_length);
|
FledastyError fledasty_utf8_string_insert_after_string(FledastyUtf8String *current_string, unsigned char *after_character_string, size_t after_character_string_length, unsigned char *character_string, size_t character_string_length);
|
||||||
FledastyError fledasty_utf8_string_insert_at_index(FledastyUtf8String *current_string, size_t index, unsigned char *character_string, size_t character_string_length);
|
FledastyError fledasty_utf8_string_insert_at_index(FledastyUtf8String *current_string, size_t index, unsigned char *character_string, size_t character_string_length);
|
||||||
|
|
||||||
|
bool fledasty_utf8_string_has_string(const FledastyUtf8String *current_string, unsigned char *character_string, size_t character_string_length);
|
||||||
static inline bool fledasty_utf8_string_is_empty(const FledastyUtf8String *current_string) { return current_string == NULL || current_string->size == 0; }
|
static inline bool fledasty_utf8_string_is_empty(const FledastyUtf8String *current_string) { return current_string == NULL || current_string->size == 0; }
|
||||||
|
|
||||||
FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const size_t size);
|
FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const size_t size);
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,23 @@ FledastyError fledasty_utf8_string_insert_at_index(FledastyUtf8String *current_s
|
||||||
return FLEDASTY_ERROR_NONE;
|
return FLEDASTY_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fledasty_utf8_string_has_string(const FledastyUtf8String *current_string, unsigned char *character_string, size_t character_string_length) {
|
||||||
|
if (current_string == NULL || character_string == NULL || character_string_length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < current_string->size - character_string_length) {
|
||||||
|
if (hallocy_compare_memory(current_string->character_string + index, character_string, character_string_length)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const size_t size) {
|
FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const size_t size) {
|
||||||
FledastyUtf8String utf8_string;
|
FledastyUtf8String utf8_string;
|
||||||
fledasty_utf8_string_initialize(&utf8_string, NULL, 0);
|
fledasty_utf8_string_initialize(&utf8_string, NULL, 0);
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,10 @@ int main() {
|
||||||
fledasty_utf8_string_insert_at_index(&test_utf8_string, test_utf8_string.size - 1, (unsigned char*)"index", 5);
|
fledasty_utf8_string_insert_at_index(&test_utf8_string, test_utf8_string.size - 1, (unsigned char*)"index", 5);
|
||||||
printf("Insert at Index: %s\n", test_utf8_string.character_string);
|
printf("Insert at Index: %s\n", test_utf8_string.character_string);
|
||||||
|
|
||||||
|
if (fledasty_utf8_string_has_string(&test_utf8_string, (unsigned char*)"😀", 4)) {
|
||||||
|
printf("String contains 😀!\n");
|
||||||
|
}
|
||||||
|
|
||||||
size_t unicode_length = 0;
|
size_t unicode_length = 0;
|
||||||
uint32_t *unicode = fledasty_utf8_string_decode(&test_utf8_string, &unicode_length);
|
uint32_t *unicode = fledasty_utf8_string_decode(&test_utf8_string, &unicode_length);
|
||||||
FledastyUtf8String encoded_string = fledasty_utf8_string_encode(unicode, unicode_length);
|
FledastyUtf8String encoded_string = fledasty_utf8_string_encode(unicode, unicode_length);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue