From d5efab49936a8ef4fb6af55a5f88b4bb1167f05c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 17 Jan 2016 16:42:19 +0900 Subject: [PATCH] src: Add inequality operator for StringRef --- src/template.h | 16 ++++++++++++++++ src/template_test.cc | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/template.h b/src/template.h index 82286367..f4650ad3 100644 --- a/src/template.h +++ b/src/template.h @@ -342,6 +342,22 @@ inline bool operator==(const char *lhs, const StringRef &rhs) { return rhs == lhs; } +inline bool operator!=(const StringRef &lhs, const std::string &rhs) { + return !(lhs == rhs); +} + +inline bool operator!=(const std::string &lhs, const StringRef &rhs) { + return !(rhs == lhs); +} + +inline bool operator!=(const StringRef &lhs, const char *rhs) { + return !(lhs == rhs); +} + +inline bool operator!=(const char *lhs, const StringRef &rhs) { + return !(rhs == lhs); +} + inline int run_app(std::function app, int argc, char **argv) { try { diff --git a/src/template_test.cc b/src/template_test.cc index df99c556..c4b7e672 100644 --- a/src/template_test.cc +++ b/src/template_test.cc @@ -87,6 +87,14 @@ void test_template_immutable_string(void) { CU_ASSERT("bravo" == from_lit); CU_ASSERT(5 == from_lit.size()); + + // equality + ImmutableString eq("delta"); + + CU_ASSERT("delta1" != eq); + CU_ASSERT("delt" != eq); + CU_ASSERT(eq != "delta1"); + CU_ASSERT(eq != "delt"); } void test_template_string_ref(void) {