summaryrefslogtreecommitdiff
path: root/AK/AKString.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-08 18:30:40 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-08 18:32:09 +0200
commit6a51093ab14444b9b513ef42fbc51b85dd346f55 (patch)
tree0a251a0fd6bdcc0a5cdb998565e1150d42425662 /AK/AKString.h
parent8b1154f5f24fe775aaa23c85bec676c5d0131b91 (diff)
downloadserenity-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.h14
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();