addded String::contains defs

This commit is contained in:
Edward R. Gonzalez 2024-11-29 14:50:54 -05:00
parent 81a0376c99
commit e3c2a577ba
3 changed files with 40 additions and 2 deletions

View File

@ -24,7 +24,7 @@
{ \ { \
if ( ! ( cond ) ) \ 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(); \ GEN_DEBUG_TRAP(); \
} \ } \
} while ( 0 ) } while ( 0 )

View File

@ -5,7 +5,7 @@
#pragma region Memory #pragma region Memory
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) ) #define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
#define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) ) #define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) )
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) ) #define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) ) #define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )

View File

@ -168,6 +168,44 @@ struct String
return Data[ length() - 1 ]; 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 ssize capacity() const
{ {
Header const& Header const&