Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
enriched_string.h
Go to the documentation of this file.
1/*
2Copyright (C) 2013 xyz, Ilya Zhuravlev <whatever@xyz.is>
3Copyright (C) 2016 Nore, Nathanaƫlle Courant <nore@mesecons.net>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <string>
23#include <string_view>
24#include <vector>
25#include <SColor.h>
26
27using namespace irr;
28
30public:
32 EnrichedString(std::wstring_view s,
33 const video::SColor &color = video::SColor(255, 255, 255, 255));
34 EnrichedString(std::wstring_view string,
35 const std::vector<video::SColor> &colors);
36 EnrichedString &operator=(std::wstring_view s);
37
38 void clear();
39
40 void addAtEnd(std::wstring_view s, video::SColor color);
41
42 // Adds the character source[i] at the end.
43 // An EnrichedString should always be able to be copied
44 // to the end of an existing EnrichedString that way.
45 void addChar(const EnrichedString &source, size_t i);
46
47 // Adds a single character at the end, without specifying its
48 // color. The color used will be the one from the last character.
49 void addCharNoColor(wchar_t c);
50
51 EnrichedString getNextLine(size_t *pos) const;
52 EnrichedString substr(size_t pos = 0, size_t len = std::string::npos) const;
53
54 EnrichedString operator+(const EnrichedString &other) const;
55 void operator+=(const EnrichedString &other);
56 void operator+=(std::wstring_view other)
57 {
58 *this += EnrichedString(other);
59 }
60
61 const wchar_t *c_str() const
62 {
63 return getString().c_str();
64 }
65 const std::vector<video::SColor> &getColors() const;
66 const std::wstring &getString() const;
67
68 inline void setDefaultColor(video::SColor color)
69 {
70 m_default_color = color;
72 }
73 void updateDefaultColor();
74 inline const video::SColor &getDefaultColor() const
75 {
76 return m_default_color;
77 }
78
79 inline bool operator==(const EnrichedString &other) const
80 {
81 return (m_string == other.m_string && m_colors == other.m_colors);
82 }
83 inline bool operator!=(const EnrichedString &other) const
84 {
85 return !(*this == other);
86 }
87 inline bool empty() const
88 {
89 return m_string.empty();
90 }
91 inline size_t size() const
92 {
93 return m_string.size();
94 }
95
96 inline bool hasBackground() const
97 {
98 return m_has_background;
99 }
100 inline video::SColor getBackground() const
101 {
102 return m_background;
103 }
104 inline void setBackground(video::SColor color)
105 {
106 m_background = color;
107 m_has_background = true;
108 }
109
110private:
111 std::wstring m_string;
112 std::vector<video::SColor> m_colors;
114 video::SColor m_default_color;
115 video::SColor m_background;
116 // This variable defines the length of the default-colored text.
118};
Definition enriched_string.h:29
video::SColor getBackground() const
Definition enriched_string.h:100
EnrichedString getNextLine(size_t *pos) const
Definition enriched_string.cpp:164
void addAtEnd(std::wstring_view s, video::SColor color)
Definition enriched_string.cpp:63
void setBackground(video::SColor color)
Definition enriched_string.h:104
bool empty() const
Definition enriched_string.h:87
void addChar(const EnrichedString &source, size_t i)
Definition enriched_string.cpp:128
EnrichedString(std::wstring_view string, const std::vector< video::SColor > &colors)
void clear()
Definition enriched_string.cpp:46
bool operator!=(const EnrichedString &other) const
Definition enriched_string.h:83
const std::vector< video::SColor > & getColors() const
Definition enriched_string.cpp:201
bool operator==(const EnrichedString &other) const
Definition enriched_string.h:79
bool hasBackground() const
Definition enriched_string.h:96
const std::wstring & getString() const
Definition enriched_string.cpp:206
void operator+=(std::wstring_view other)
Definition enriched_string.h:56
std::wstring m_string
Definition enriched_string.h:111
const wchar_t * c_str() const
Definition enriched_string.h:61
video::SColor m_default_color
Definition enriched_string.h:114
std::vector< video::SColor > m_colors
Definition enriched_string.h:112
void operator+=(const EnrichedString &other)
Definition enriched_string.cpp:151
const video::SColor & getDefaultColor() const
Definition enriched_string.h:74
void addCharNoColor(wchar_t c)
Definition enriched_string.cpp:134
size_t size() const
Definition enriched_string.h:91
bool m_has_background
Definition enriched_string.h:113
EnrichedString operator+(const EnrichedString &other) const
Definition enriched_string.cpp:144
EnrichedString()
Definition enriched_string.cpp:27
EnrichedString(std::wstring_view s, const video::SColor &color=video::SColor(255, 255, 255, 255))
void updateDefaultColor()
Definition enriched_string.cpp:211
size_t m_default_length
Definition enriched_string.h:117
EnrichedString substr(size_t pos=0, size_t len=std::string::npos) const
Definition enriched_string.cpp:179
void setDefaultColor(video::SColor color)
Definition enriched_string.h:68
video::SColor m_background
Definition enriched_string.h:115
EnrichedString & operator=(std::wstring_view s)
Definition enriched_string.cpp:56
Definition clientmap.h:30