Browse Source

string: implement String::Last() and a constructor for fixed-length strings.

legacy
Sam Hocevar sam 12 years ago
parent
commit
6ce17605a7
1 changed files with 20 additions and 5 deletions
  1. +20
    -5
      src/lol/base/string.h

+ 20
- 5
src/lol/base/string.h View File

@@ -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;


Loading…
Cancel
Save