2 Copyright (C) 2013 xyz, Ilya Zhuravlev <whatever@xyz.is>
3 Copyright (C) 2016 Nore, Nathanaƫlle Courant <nore@mesecons.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 class EnrichedString {
31 EnrichedString(const std::wstring &s,
32 const video::SColor &color = video::SColor(255, 255, 255, 255));
33 EnrichedString(const wchar_t *str,
34 const video::SColor &color = video::SColor(255, 255, 255, 255));
35 EnrichedString(const std::wstring &string,
36 const std::vector<video::SColor> &colors);
37 void operator=(const wchar_t *str);
41 void addAtEnd(const std::wstring &s, video::SColor color);
43 // Adds the character source[i] at the end.
44 // An EnrichedString should always be able to be copied
45 // to the end of an existing EnrichedString that way.
46 void addChar(const EnrichedString &source, size_t i);
48 // Adds a single character at the end, without specifying its
49 // color. The color used will be the one from the last character.
50 void addCharNoColor(wchar_t c);
52 EnrichedString substr(size_t pos = 0, size_t len = std::string::npos) const;
53 EnrichedString operator+(const EnrichedString &other) const;
54 void operator+=(const EnrichedString &other);
55 const wchar_t *c_str() const;
56 const std::vector<video::SColor> &getColors() const;
57 const std::wstring &getString() const;
59 inline void setDefaultColor(video::SColor color)
61 m_default_color = color;
64 void updateDefaultColor();
65 inline const video::SColor &getDefaultColor() const
67 return m_default_color;
70 inline bool operator==(const EnrichedString &other) const
72 return (m_string == other.m_string && m_colors == other.m_colors);
74 inline bool operator!=(const EnrichedString &other) const
76 return !(*this == other);
78 inline bool empty() const
80 return m_string.empty();
82 inline size_t size() const
84 return m_string.size();
87 inline bool hasBackground() const
89 return m_has_background;
91 inline video::SColor getBackground() const
95 inline void setBackground(video::SColor color)
98 m_has_background = true;
102 std::wstring m_string;
103 std::vector<video::SColor> m_colors;
104 bool m_has_background;
105 video::SColor m_default_color;
106 video::SColor m_background;
107 // This variable defines the length of the default-colored text.
108 // Change this to a std::vector if an "end coloring" tag is wanted.
109 size_t m_default_length = 0;