sptk2 logo
SPTK Home Page
String.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include "sptk.h"
30#include "string_ext.h"
31#include <algorithm>
32#include <string>
33
34namespace sptk {
35
41class Strings;
42
47class SP_EXPORT String
48 : public std::string
49{
50public:
55 : m_id(0)
56 {
57 }
58
63 String(const String& other) = default;
64
69 String(String&& src) noexcept = default;
70
76 String(const std::string& str, int64_t id = 0)
77 : std::string(str)
78 , m_id(id)
79 {
80 }
81
87 String(const char* str)
88 : std::string(str)
89 , m_id(0)
90 {
91 }
92
99 String(const char* str, size_t len, int64_t id = 0)
100 : std::string(str, len)
101 , m_id(id)
102 {
103 }
104
111 String(size_t len, char ch, int64_t id = 0)
112 : std::string(len, ch)
113 , m_id(id)
114 {
115 }
116
120 ~String() noexcept = default;
121
126 String& operator=(const std::string& si)
127 {
128 assign(si);
129 m_id = 0;
130 return *this;
131 }
132
137 String& operator=(const String& other) = default;
146 String& operator=(String&& other) noexcept = default;
147
152 String& operator=(const char* str)
153 {
154 assign(str);
155 m_id = 0;
156 return *this;
157 }
158
162 int64_t ident() const
163 {
164 return m_id;
165 }
166
170 void ident(int64_t id)
171 {
172 m_id = id;
173 }
174
180 bool in(std::initializer_list<String> list) const;
181
187 bool matches(const String& pattern, const String& options = String()) const;
188
193 Strings split(const String& pattern) const;
194
203 String replace(const String& pattern, const String& replacement) const;
204
209
214
218 int toInt() const;
219
224 bool startsWith(const String& subject) const;
225
230 bool contains(const String& subject) const;
231
236 bool endsWith(const String& subject) const;
237
241 String trim() const;
242
243private:
247 int64_t m_id {0};
248};
249
250} // namespace sptk
Definition: String.h:49
Definition: Strings.h:52
String replace(const String &pattern, const String &replacement) const
~String() noexcept=default
int toInt() const
String()
Definition: String.h:54
String(size_t len, char ch, int64_t id=0)
Definition: String.h:111
bool endsWith(const String &subject) const
String(String &&src) noexcept=default
String(const std::string &str, int64_t id=0)
Definition: String.h:76
bool in(std::initializer_list< String > list) const
String & operator=(String &&other) noexcept=default
bool matches(const String &pattern, const String &options=String()) const
String & operator=(const String &other)=default
String toUpperCase() const
bool startsWith(const String &subject) const
int64_t ident() const
Definition: String.h:162
String & operator=(const char *str)
Definition: String.h:152
void ident(int64_t id)
Definition: String.h:170
String(const char *str)
Definition: String.h:87
String(const String &other)=default
bool contains(const String &subject) const
String toLowerCase() const
String trim() const
String(const char *str, size_t len, int64_t id=0)
Definition: String.h:99
Strings split(const String &pattern) const

Fri Oct 14 2022 09:58:32: SPTK 5.4.1