xo-object: + DString.compare() + utest
This commit is contained in:
parent
c7ff46bd36
commit
3052ecdbcf
3 changed files with 30 additions and 1 deletions
|
|
@ -164,6 +164,11 @@ namespace xo {
|
|||
return size_;
|
||||
}
|
||||
|
||||
/** lexicographically compare two strings.
|
||||
* @return <0 if lhs < rhs, 0 if equal, >0 if lhs > rhs
|
||||
**/
|
||||
static int compare(const DString & lhs, const DString & rhs) noexcept;
|
||||
|
||||
// TODO - behave like std::string, to the extent feasible
|
||||
// insert
|
||||
// insert_range
|
||||
|
|
@ -181,7 +186,6 @@ namespace xo {
|
|||
// find_first_not_of
|
||||
// find_last_of
|
||||
// find_last_not_of
|
||||
// compare
|
||||
// starts_with
|
||||
// end_with
|
||||
// contains
|
||||
|
|
|
|||
|
|
@ -84,6 +84,12 @@ namespace xo {
|
|||
return *this;
|
||||
}
|
||||
|
||||
int
|
||||
DString::compare(const DString & lhs, const DString & rhs) noexcept
|
||||
{
|
||||
return ::strcmp(lhs.chars_, rhs.chars_);
|
||||
}
|
||||
|
||||
auto
|
||||
DString::fixup_size() noexcept -> size_type
|
||||
{
|
||||
|
|
|
|||
|
|
@ -292,6 +292,25 @@ namespace xo {
|
|||
REQUIRE(s->size() == 7);
|
||||
REQUIRE(std::strcmp(s->chars(), "hello w") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("DString-compare", "[object2][DString]")
|
||||
{
|
||||
ArenaConfig cfg { .name_ = "testarena",
|
||||
.size_ = 4*1024 };
|
||||
DArena arena = DArena::map(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
DString * s1 = DString::from_cstr(alloc, "apple");
|
||||
DString * s2 = DString::from_cstr(alloc, "apple");
|
||||
DString * s3 = DString::from_cstr(alloc, "banana");
|
||||
DString * s4 = DString::from_cstr(alloc, "aardvark");
|
||||
|
||||
REQUIRE(DString::compare(*s1, *s2) == 0);
|
||||
REQUIRE(DString::compare(*s1, *s3) < 0);
|
||||
REQUIRE(DString::compare(*s3, *s1) > 0);
|
||||
REQUIRE(DString::compare(*s1, *s4) > 0);
|
||||
REQUIRE(DString::compare(*s4, *s1) < 0);
|
||||
}
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue