ManaPlus
stringutils.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2007-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef UTILS_STRINGUTILS_H
24 #define UTILS_STRINGUTILS_H
25 
26 #include "utils/stringvector.h"
27 
28 #include <list>
29 #include <set>
30 
31 #include "localconsts.h"
32 
39 std::string &trim(std::string &str);
40 
47 std::string &toLower(std::string &str);
48 
55 std::string &toUpper(std::string &str);
56 
57 
64 unsigned int atox(const std::string &str) A_WARN_UNUSED;
65 
72 std::string toString(uint32_t num);
73 
74 std::string toString(uint64_t num);
75 
76 std::string toString(unsigned char num);
77 
78 std::string toString(int32_t num);
79 
80 std::string toString(uint16_t num);
81 
82 std::string toString(const float num);
83 
84 std::string toString(const double num);
85 
86 std::string toStringPrint(const unsigned int val);
87 
97 const char *ipToString(const uint32_t address) A_WARN_UNUSED;
98 
102 std::string strprintf(const char *const format, ...) A_NONNULL(1) A_WARN_UNUSED
103 #ifdef __GNUC__
104 #ifdef __OpenBSD__
105  __attribute__((__format__(printf, 1, 2)))
106 #else // __OpenBSD__
107  __attribute__((__format__(gnu_printf, 1, 2)))
108 #endif // __OpenBSD__
109 #endif // __GNUC__
110 ;
111 
118 std::string removeColors(std::string msg) A_WARN_UNUSED;
119 
120 const std::string findSameSubstring(const std::string &restrict str1,
121  const std::string &restrict str2);
122 
123 const std::string findSameSubstringI(const std::string &restrict str1,
124  const std::string &restrict str2);
125 
134 int compareStrI(const std::string &a, const std::string &b) A_WARN_UNUSED;
135 
139 constexpr inline bool isWordSeparator(const signed char chr)
140  A_CONST A_WARN_UNUSED;
141 constexpr inline bool isWordSeparator(const signed char chr)
142 {
143  return chr == ' ' ||
144  chr == ',' ||
145  chr == '.' ||
146  chr == '"';
147 }
148 
149 size_t findI(std::string str, std::string subStr) A_WARN_UNUSED;
150 
151 size_t findI(std::string text, const StringVect &list) A_WARN_UNUSED;
152 
153 size_t findAny(const std::string &restrict text,
154  const std::string &restrict chars,
155  const size_t pos) A_WARN_UNUSED;
156 
157 const std::string encodeStr(unsigned int value,
158  const unsigned int size) A_WARN_UNUSED;
159 
160 unsigned int decodeStr(const std::string &str) A_WARN_UNUSED;
161 
162 std::string extractNameFromSprite(std::string str) A_WARN_UNUSED;
163 
164 std::string removeSpriteIndex(std::string str) A_WARN_UNUSED;
165 
166 const char* getSafeUtf8String(const std::string &text) A_WARN_UNUSED;
167 
168 void getSafeUtf8String(std::string text, char *const buf);
169 
170 std::string getFileName(const std::string &path) A_WARN_UNUSED;
171 
172 std::string getFileDir(const std::string &path) A_WARN_UNUSED;
173 
174 std::string& replaceAll(std::string& context,
175  const std::string &restrict from,
176  const std::string &restrict to);
177 
178 void replaceRecursiveAll(std::string& context,
179  const std::string &restrict from,
180  const char to);
181 
188 bool getBoolFromString(const std::string &text) A_WARN_UNUSED;
189 
190 void replaceSpecialChars(std::string &text);
191 
195 std::string normalize(const std::string &name) A_WARN_UNUSED;
196 
197 void splitToIntSet(std::set<int> &tokens, const std::string &text,
198  const char separator);
199 
200 std::list<int> splitToIntList(const std::string &text,
201  const char separator) A_WARN_UNUSED;
202 
203 std::list<std::string> splitToStringList(const std::string &text,
204  const char separator) A_WARN_UNUSED;
205 
206 void splitToStringVector(StringVect &tokens,
207  const std::string &text, const char separator);
208 
209 void splitToStringSet(std::set<std::string> &tokens,
210  const std::string &text, const char separator);
211 
212 void splitToIntVector(STD_VECTOR<int> &tokens,
213  const std::string &text, const char separator);
214 
215 std::string combineDye(std::string file, const std::string &dye) A_WARN_UNUSED;
216 
217 std::string combineDye2(std::string file,
218  const std::string &dye) A_WARN_UNUSED;
219 
220 std::string combineDye3(std::string file,
221  const std::string &dye) A_WARN_UNUSED;
222 
223 std::string packList(const std::list<std::string> &list) A_WARN_UNUSED;
224 
225 std::list<std::string> unpackList(const std::string &str) A_WARN_UNUSED;
226 
227 std::string stringToHexPath(const std::string &str) A_WARN_UNUSED;
228 
229 void deleteCharLeft(std::string &str, unsigned *const pos);
230 
231 bool findLast(const std::string &restrict str1,
232  const std::string &restrict str2) A_WARN_UNUSED;
233 
234 bool findFirst(const std::string &restrict str1,
235  const std::string &restrict str2) A_WARN_UNUSED;
236 
237 bool findCutLast(std::string &restrict str1,
238  const std::string &restrict str2) A_WARN_UNUSED;
239 
240 void cutLast(std::string &restrict str1,
241  const std::string &restrict str2);
242 
243 bool findCutFirst(std::string &restrict str1,
244  const std::string &restrict str2);
245 
246 void cutFirst(std::string &restrict str1,
247  const std::string &restrict str2);
248 
249 std::string &removeProtocol(std::string &url);
250 
251 bool strStartWith(const std::string &restrict str,
252  const std::string &restrict start) A_WARN_UNUSED;
253 
254 std::string getDateString() A_WARN_UNUSED;
255 
256 std::string getDateTimeString() A_WARN_UNUSED;
257 
258 signed char parseBoolean(const std::string &value);
259 
260 std::string encodeLinkText(std::string data);
261 
262 std::string decodeLinkText(std::string data);
263 
264 bool isDigit(const std::string &str);
265 
266 void secureChatCommand(std::string &str);
267 
268 bool parse2Int(const std::string &args, int &x, int &y);
269 
270 bool parse2Str(const std::string &args, std::string &str1, std::string &str2);
271 
272 uint32_t parseNumber(const std::string &str);
273 
274 std::string removeToken(std::string &str, const std::string &token);
275 
276 std::string timeToStr(const uint32_t time);
277 
278 std::string timeDiffToString(int timeDiff);
279 
280 void replaceItemLinks(std::string &msg);
281 
282 std::string escapeString(std::string str);
283 
284 void sanitizePath(std::string &path);
285 
286 std::string pathJoin(std::string str1,
287  const std::string &str2);
288 
289 std::string pathJoin(std::string str1,
290  const std::string &str2,
291  const std::string &str3);
292 
293 std::string urlJoin(std::string str1,
294  const std::string &str2);
295 
296 #endif // UTILS_STRINGUTILS_H
std::string timeDiffToString(int timeDiff)
std::string combineDye3(std::string file, const std::string &dye)
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)
bool getBoolFromString(const std::string &text)
std::string combineDye2(std::string file, const std::string &dye)
EAthena::ItemHandler __attribute__
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
bool strStartWith(const std::string &str, const std::string &start)
std::string timeToStr(const uint32_t time)
bool findCutFirst(std::string &str1, const std::string &str2)
std::string toStringPrint(const unsigned int val)
void cutFirst(std::string &str1, const std::string &str2)
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
#define A_WARN_UNUSED
Definition: localconsts.h:152
#define constexpr
Definition: localconsts.h:47
std::string pathJoin(std::string str1, const std::string &str2)
std::string removeSpriteIndex(std::string str)
bool msg(InputEvent &event)
Definition: chat.cpp:38
std::string getFileDir(const std::string &path)
std::string getDateString()
bool parse2Str(const std::string &args, std::string &str1, std::string &str2)
std::vector< std::string > StringVect
Definition: stringvector.h:28
size_t findI(std::string str, std::string subStr)
#define A_NONNULL(...)
Definition: localconsts.h:159
int compareStrI(const std::string &a, const std::string &b)
bool findLast(const std::string &str1, const std::string &str2)
std::string & trim(std::string &str)
Definition: stringutils.cpp:46
std::string removeColors(std::string msg)
bool isWordSeparator(const signed char chr) A_CONST
Definition: stringutils.h:141
const char * getSafeUtf8String(const std::string &text)
#define gnu_printf
Definition: localconsts.h:154
std::string removeToken(std::string &str, const std::string &token)
const char * ipToString(const uint32_t address)
Definition: stringutils.cpp:85
void secureChatCommand(std::string &str)
void replaceSpecialChars(std::string &text)
bool findFirst(const std::string &str1, const std::string &str2)
std::string urlJoin(std::string str1, const std::string &str2)
signed char parseBoolean(const std::string &value)
std::string encodeLinkText(std::string data)
void splitToStringSet(std::set< std::string > &tokens, const std::string &text, const char separator)
uint32_t data
std::string extractNameFromSprite(std::string str)
std::string normalize(const std::string &name)
void splitToIntSet(std::set< int > &tokens, const std::string &text, const char separator)
bool findCutLast(std::string &str1, const std::string &str2)
std::list< int > splitToIntList(const std::string &text, const char separator)
unsigned int decodeStr(const std::string &str)
void cutLast(std::string &str1, const std::string &str2)
std::string stringToHexPath(const std::string &str)
void deleteCharLeft(std::string &str, unsigned *const pos)
std::string packList(const std::list< std::string > &list)
std::list< std::string > unpackList(const std::string &str)
std::string toString(uint32_t num)
void sanitizePath(std::string &path)
bool isDigit(const std::string &str)
std::string & removeProtocol(std::string &url)
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
const std::string encodeStr(unsigned int value, const unsigned int size)
const std::string findSameSubstringI(const std::string &str1, const std::string &str2)
size_t findAny(const std::string &text, const std::string &chars, const size_t pos)
std::list< std::string > splitToStringList(const std::string &text, const char separator)
std::string & toUpper(std::string &str)
Definition: stringutils.cpp:71
std::string decodeLinkText(std::string data)
unsigned int atox(const std::string &str)
Definition: stringutils.cpp:77
#define restrict
Definition: localconsts.h:156
void replaceRecursiveAll(std::string &context, const std::string &from, const char to)
const std::string findSameSubstring(const std::string &str1, const std::string &str2)
bool parse2Int(const std::string &args, int &x, int &y)
std::string escapeString(std::string str)
std::string & toLower(std::string &str)
Definition: stringutils.cpp:65
bool url(InputEvent &event)
Definition: commands.cpp:63
std::string getFileName(const std::string &path)
uint32_t parseNumber(const std::string &str)
std::string getDateTimeString()
void replaceItemLinks(std::string &msg)
std::string combineDye(std::string file, const std::string &dye)