diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-08 18:30:40 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-08 18:32:09 +0200 |
commit | 6a51093ab14444b9b513ef42fbc51b85dd346f55 (patch) | |
tree | 0a251a0fd6bdcc0a5cdb998565e1150d42425662 /AK/AKString.h | |
parent | 8b1154f5f24fe775aaa23c85bec676c5d0131b91 (diff) | |
download | serenity-6a51093ab14444b9b513ef42fbc51b85dd346f55.zip |
AK: Add String::operator==(const char*).
Without this function, comparing a String to a const char* will instantiate
a temporary String which is obviously not great.
Also add some missing null checks to StringView::operator==(const char*).
Diffstat (limited to 'AK/AKString.h')
-rw-r--r-- | AK/AKString.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/AK/AKString.h b/AK/AKString.h index 612dae31cc..86108dae16 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -133,6 +133,20 @@ public: bool operator!=(const String& other) const { return !(*this == other); } bool operator<(const String&) const; + bool operator==(const char* cstring) const + { + if (is_null()) + return !cstring; + if (!cstring) + return false; + return !strcmp(characters(), cstring); + } + + bool operator!=(const char* cstring) const + { + return !(*this == cstring); + } + String isolated_copy() const; static String empty(); |