From e3c2a577ba73a585679933a68b10620cd9415e59 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 29 Nov 2024 14:50:54 -0500 Subject: [PATCH] addded String::contains defs --- project/dependencies/debug.hpp | 2 +- project/dependencies/memory.hpp | 2 +- project/dependencies/strings.hpp | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/project/dependencies/debug.hpp b/project/dependencies/debug.hpp index cc44c7f..3b041bd 100644 --- a/project/dependencies/debug.hpp +++ b/project/dependencies/debug.hpp @@ -24,7 +24,7 @@ { \ if ( ! ( cond ) ) \ { \ - assert_handler( #cond, __FILE__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \ + assert_handler( #cond, __FILE__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \ GEN_DEBUG_TRAP(); \ } \ } while ( 0 ) diff --git a/project/dependencies/memory.hpp b/project/dependencies/memory.hpp index a7bcf7b..889749b 100644 --- a/project/dependencies/memory.hpp +++ b/project/dependencies/memory.hpp @@ -5,7 +5,7 @@ #pragma region Memory -#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) ) +#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) ) #define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) ) #define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) ) #define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) ) diff --git a/project/dependencies/strings.hpp b/project/dependencies/strings.hpp index edb3c8c..0db7d54 100644 --- a/project/dependencies/strings.hpp +++ b/project/dependencies/strings.hpp @@ -168,6 +168,44 @@ struct String return Data[ length() - 1 ]; } + bool contains(StrC substring) const + { + Header const& header = * rcast( Header const*, Data - sizeof( Header )); + + if (substring.Len > header.Length) + return false; + + ssize main_len = header.Length; + ssize sub_len = substring.Len; + + for (ssize idx = 0; idx <= main_len - sub_len; ++idx) + { + if (str_compare(Data + idx, substring.Ptr, sub_len) == 0) + return true; + } + + return false; + } + + bool contains(String const& substring) const + { + Header const& header = * rcast( Header const*, Data - sizeof( Header )); + + if (substring.length() > header.Length) + return false; + + ssize main_len = header.Length; + ssize sub_len = substring.length(); + + for (ssize idx = 0; idx <= main_len - sub_len; ++idx) + { + if (str_compare(Data + idx, substring.Data, sub_len) == 0) + return true; + } + + return false; + } + ssize capacity() const { Header const&