Browse Source

String: operator < implementation

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
2998673ed0
2 changed files with 23 additions and 0 deletions
  1. +12
    -0
      src/lol/base/string.h
  2. +11
    -0
      src/t/base/string.cpp

+ 12
- 0
src/lol/base/string.h View File

@@ -276,6 +276,18 @@ public:
return !(*this == sz);
}

inline bool operator <(String const & that)
{
auto it_this = begin(*this);
auto it_that = begin(that);

for ( ; it_this != end(*this) && it_that != end(that) ; ++it_this, ++it_that)
if (*it_this < *it_that)
return true;

return (!(it_this != end(*this)) && (it_that != end(that)));
}

#ifdef __GNUC__
# define LOL_FMT_ATTR(n, p) __attribute__((format(printf, n, p)))
#else


+ 11
- 0
src/t/base/string.cpp View File

@@ -227,6 +227,17 @@ lolunit_declare_fixture(StringTest)
lolunit_assert(!s.EndsWith("olol"));
lolunit_assert(!s.EndsWith("lolilolilol"));
}

lolunit_declare_test(StringCompare)
{
String s1 = "lolilol";
String s2 = s1;
String s3 = "trololol";

lolunit_assert(!(s1 < s2));
lolunit_assert(!(s2 < s1));
lolunit_assert(s1 < s3);
}
};

} /* namespace lol */


Loading…
Cancel
Save