source: trunk/src/lol/core/string.h @ 2089

Last change on this file since 2089 was 2089, checked in by sam, 8 years ago

core: compilation fix for older compilers.

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The String class
13// ----------------
14// A very simple String class, based on Array.
15//
16
17#if !defined __LOL_STRING_H__
18#define __LOL_STRING_H__
19
20#include <lol/core/array.h>
21
22namespace lol
23{
24
25class String : protected Array<char>
26{
27private:
28    typedef Array<char> Super;
29
30public:
31    inline String()
32      : Super()
33    {
34        Push('\0');
35    }
36
37    inline String(char const *str)
38      : Super()
39    {
40        do
41        {
42            Push(*str);
43        }
44        while (*str++);
45    }
46
47    inline char &operator [](int n)
48    {
49        return ((Super &)*this)[n];
50    }
51
52    inline char const &operator [](int n) const
53    {
54        return ((Super const &)*this)[n];
55    }
56
57    inline String operator +(String const &s)
58    {
59        String ret(*this);
60        return ret += s;
61    }
62
63    inline String operator +=(String const &s)
64    {
65        /* Be careful, we have a trailing zero we don't want! */
66        --m_count;
67        (Super &)*this += (Super const &)s;
68        return *this;
69    }
70};
71
72} /* namespace lol */
73
74#endif // __LOL_STRING_H__
75
Note: See TracBrowser for help on using the repository browser.