From 6ce17605a7ec51d51a089eb411d0211043022bc9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 21 Jan 2013 13:11:48 +0000 Subject: [PATCH] string: implement String::Last() and a constructor for fixed-length strings. --- src/lol/base/string.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/lol/base/string.h b/src/lol/base/string.h index 67f8a959..b4246de5 100644 --- a/src/lol/base/string.h +++ b/src/lol/base/string.h @@ -37,11 +37,16 @@ public: inline String(char const *str) : Super() { - do - { - Push(*str); - } - while (*str++); + Resize((int)strlen(str)); + memcpy(&(*this)[0], str, Count() + 1); + } + + inline String(char const *str, int count) + : Super() + { + Resize(count + 1); + memcpy(&(*this)[0], str, Count()); + ((Super &)*this).Last() = '\0'; } inline String(String const &s) @@ -59,6 +64,16 @@ public: return ((Super const &)*this)[n]; } + inline char &Last() + { + return (*this)[Count() - 1]; + } + + inline char const &Last() const + { + return (*this)[Count() - 1]; + } + inline int Count() const { return ((Super const &)*this).Count() - 1;