diff options
Diffstat (limited to 'source/fud_string.cpp')
-rw-r--r-- | source/fud_string.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/source/fud_string.cpp b/source/fud_string.cpp index 74742e1..52d6b8f 100644 --- a/source/fud_string.cpp +++ b/source/fud_string.cpp @@ -236,7 +236,7 @@ FudStatus String::pushBack(const FudUtf8& letter) return FudStatus::Success; } -FudStatus String::catenate(StringView source) +FudStatus String::append(StringView source) { if (!valid()) { return FudStatus::StringInvalid; @@ -262,13 +262,19 @@ FudStatus String::catenate(StringView source) return status; } -String String::append(const String& rhs) const +String String::catenate(const char* rhs) const +{ + String rhsString{rhs}; + return catenate(rhsString); +} + +String String::catenate(const String& rhs) const { String output{}; output.m_length = 1; output.m_capacity = 0; - if (!valid()) { + if (!valid() || !rhs.valid()) { return output; } @@ -279,7 +285,9 @@ String String::append(const String& rhs) const } auto* destPtr = output.data(); - auto status = copyMem(destPtr, m_capacity, rhs.data(), rhs.length()); + auto status = copyMem(destPtr, m_capacity, data(), length()); + fudAssert(status == FudStatus::Success); + status = copyMem(destPtr + length(), m_capacity, rhs.data(), rhs.length()); fudAssert(status == FudStatus::Success); static_cast<void>(status); fudAssert(output.nullTerminate() == FudStatus::Success); @@ -287,6 +295,28 @@ String String::append(const String& rhs) const return output; } +bool String::compare(const String& rhs) const { + if (!valid() || !rhs.valid()) { + return false; + } + + if (length() != rhs.length()) { + return false; + } + + if (isLarge() && data() == rhs.data()) + { + return true; + } + + auto diffResult = compareMem(data(), length(), rhs.data(), rhs.length()); + if (diffResult.isError()) { + return false; + } + + return diffResult.getOkay() == 0; +} + const utf8* String::begin() const { return data(); |