mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-05 21:38:40 +00:00
moved cstring and find needle string ops to the main layer
This commit is contained in:
@@ -234,6 +234,25 @@ str16_cstring_capped(void *cstr, void *cap)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal String8
|
||||||
|
str8_cstring_capped_reverse(void *raw_start, void *raw_cap)
|
||||||
|
{
|
||||||
|
U8 *start = raw_start;
|
||||||
|
U8 *ptr = raw_cap;
|
||||||
|
for(; ptr > start; )
|
||||||
|
{
|
||||||
|
ptr -= 1;
|
||||||
|
|
||||||
|
if (*ptr == '\0')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
U64 size = (U64)(ptr - start);
|
||||||
|
String8 result = str8(start, size);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: String Stylization
|
//~ rjf: String Stylization
|
||||||
|
|
||||||
@@ -343,6 +362,22 @@ str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal U64
|
||||||
|
str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags)
|
||||||
|
{
|
||||||
|
U64 result = 0;
|
||||||
|
for(S64 i = string.size - start_pos - needle.size; i >= 0; --i)
|
||||||
|
{
|
||||||
|
String8 haystack = str8_substr(string, rng_1u64(i, i + needle.size));
|
||||||
|
if(str8_match(haystack, needle, flags))
|
||||||
|
{
|
||||||
|
result = (U64)i + needle.size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
internal B32
|
internal B32
|
||||||
str8_ends_with(String8 string, String8 end, StringMatchFlags flags){
|
str8_ends_with(String8 string, String8 end, StringMatchFlags flags){
|
||||||
String8 postfix = str8_postfix(string, end.size);
|
String8 postfix = str8_postfix(string, end.size);
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ internal String16 str16_cstring(U16 *c);
|
|||||||
internal String32 str32_cstring(U32 *c);
|
internal String32 str32_cstring(U32 *c);
|
||||||
internal String8 str8_cstring_capped(void *cstr, void *cap);
|
internal String8 str8_cstring_capped(void *cstr, void *cap);
|
||||||
internal String16 str16_cstring_capped(void *cstr, void *cap);
|
internal String16 str16_cstring_capped(void *cstr, void *cap);
|
||||||
|
internal String8 str8_cstring_capped_reverse(void *raw_start, void *raw_cap);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: String Stylization
|
//~ rjf: String Stylization
|
||||||
@@ -207,6 +208,7 @@ internal String8 backslashed_from_str8(Arena *arena, String8 string);
|
|||||||
|
|
||||||
internal B32 str8_match(String8 a, String8 b, StringMatchFlags flags);
|
internal B32 str8_match(String8 a, String8 b, StringMatchFlags flags);
|
||||||
internal U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
internal U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||||
|
internal U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||||
internal B32 str8_ends_with(String8 string, String8 end, StringMatchFlags flags);
|
internal B32 str8_ends_with(String8 string, String8 end, StringMatchFlags flags);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@@ -1,33 +1,6 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
global read_only String8 g_null_string;
|
|
||||||
|
|
||||||
internal String8
|
|
||||||
str8_cstring_capped_reverse(void *start, void *cap)
|
|
||||||
{
|
|
||||||
char *ptr = cap;
|
|
||||||
while (ptr > (char *)start) {
|
|
||||||
--ptr;
|
|
||||||
if (*ptr == '\0') break;
|
|
||||||
}
|
|
||||||
U64 null_offset = (U64)(ptr - (char *) start);
|
|
||||||
String8 result = str8((U8 *) start, null_offset);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal U64
|
|
||||||
str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags)
|
|
||||||
{
|
|
||||||
for (S64 i = string.size - start_pos - needle.size; i >= 0; --i) {
|
|
||||||
String8 haystack = str8_substr(string, rng_1u64(i, i + needle.size));
|
|
||||||
if (str8_match(haystack, needle, flags)) {
|
|
||||||
return (U64)i + needle.size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal int
|
internal int
|
||||||
str8_compar(String8 a, String8 b, B32 ignore_case)
|
str8_compar(String8 a, String8 b, B32 ignore_case)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
#define MemoryCopyStr8(dst, s) MemoryCopy(dst, (s).str, (s).size)
|
#define MemoryCopyStr8(dst, s) MemoryCopy(dst, (s).str, (s).size)
|
||||||
|
|
||||||
internal String8 str8_cstring_capped_reverse(void *start, void *cap);
|
|
||||||
|
|
||||||
internal U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
|
||||||
|
|
||||||
internal int str8_compar(String8 a, String8 b, B32 ignore_case);
|
internal int str8_compar(String8 a, String8 b, B32 ignore_case);
|
||||||
internal int str8_compar_ignore_case(const void *a, const void *b);
|
internal int str8_compar_ignore_case(const void *a, const void *b);
|
||||||
internal int str8_compar_case_sensitive(const void *a, const void *b);
|
internal int str8_compar_case_sensitive(const void *a, const void *b);
|
||||||
|
|||||||
Reference in New Issue
Block a user