nasal::String: add ends_with method
This commit is contained in:
@@ -136,6 +136,12 @@ namespace nasal
|
||||
return rhs.size() <= size() && compare(0, npos, rhs) == 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool String::ends_with(const String& rhs) const
|
||||
{
|
||||
return rhs.size() <= size() && compare(size() - rhs.size(), npos, rhs) == 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
size_t String::find(const char c, size_t pos) const
|
||||
{
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace nasal
|
||||
|
||||
int compare(size_t pos, size_t len, const String& rhs) const;
|
||||
bool starts_with(const String& rhs) const;
|
||||
bool ends_with(const String& rhs) const;
|
||||
|
||||
size_t find(const char c, size_t pos = 0) const;
|
||||
size_t find_first_of(const String& chr, size_t pos = 0) const;
|
||||
|
||||
@@ -286,6 +286,13 @@ int main(int argc, char* argv[])
|
||||
VERIFY( !string.starts_with(String(c, "Test1")) );
|
||||
VERIFY( !string.starts_with(String(c, "bb")) );
|
||||
VERIFY( !string.starts_with(String(c, "bbasdasdafasd")) );
|
||||
VERIFY( string.ends_with(String(c, "t")) );
|
||||
VERIFY( string.ends_with(String(c, "st")) );
|
||||
VERIFY( string.ends_with(String(c, "est")) );
|
||||
VERIFY( string.ends_with(String(c, "Test")) );
|
||||
VERIFY( !string.ends_with(String(c, "1Test")) );
|
||||
VERIFY( !string.ends_with(String(c, "abc")) );
|
||||
VERIFY( !string.ends_with(String(c, "estasdasd")) );
|
||||
VERIFY( string.find('e') == 1 );
|
||||
VERIFY( string.find('9') == String::npos );
|
||||
VERIFY( string.find_first_of(String(c, "st")) == 2 );
|
||||
|
||||
Reference in New Issue
Block a user