Luanti 5.18.0-dev
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
8#include "config.h" // IS_CLIENT_BUILD
9#if IS_CLIENT_BUILD
10#include "irrString.h"
11#endif
12#include <cstdlib>
13#include <string>
14#include <string_view>
15#include <cstring>
16#include <vector>
17#include <limits>
18#include <sstream>
19#include <iomanip>
20#include <cctype>
21#include <cwctype>
22#include <unordered_map>
23#include <optional>
24
25class Translations;
26
27#define STRINGIFY(x) #x
28#define TOSTRING(x) STRINGIFY(x)
29
30// Checks whether a value is an ASCII printable character
31#define IS_ASCII_PRINTABLE_CHAR(x) \
32 (((unsigned int)(x) >= 0x20) && \
33 ( (unsigned int)(x) <= 0x7e))
34
35// Checks whether a value is in a Unicode private use area
36#define IS_PRIVATE_USE_CHAR16(x) \
37 ((wchar_t)(x) >= 0xE000 && \
38 (wchar_t)(x) <= 0xF8FF)
39#define IS_PRIVATE_USE_CHAR32(x) \
40 (((wchar_t)(x) >= 0xF0000 && \
41 (wchar_t)(x) <= 0xFFFFD) || \
42 ((wchar_t)(x) >= 0x100000 && \
43 (wchar_t)(x) <= 0x10FFFD))
44#if WCHAR_MAX > 0xFFFF
45#define IS_PRIVATE_USE_CHAR(x) (IS_PRIVATE_USE_CHAR16(x) || IS_PRIVATE_USE_CHAR32(x))
46#else
47#define IS_PRIVATE_USE_CHAR(x) IS_PRIVATE_USE_CHAR16(x)
48#endif
49
50// Checks whether a byte is an inner byte for an utf-8 multibyte sequence
51#define IS_UTF8_MULTB_INNER(x) \
52 (((unsigned char)(x) >= 0x80) && \
53 ( (unsigned char)(x) <= 0xbf))
54
55// Checks whether a byte is a start byte for an utf-8 multibyte sequence
56#define IS_UTF8_MULTB_START(x) \
57 (((unsigned char)(x) >= 0xc2) && \
58 ( (unsigned char)(x) <= 0xf4))
59
60// Given a start byte x for an utf-8 multibyte sequence
61// it gives the length of the whole sequence in bytes.
62#define UTF8_MULTB_START_LEN(x) \
63 (((unsigned char)(x) < 0xe0) ? 2 : \
64 (((unsigned char)(x) < 0xf0) ? 3 : 4))
65
66// Maximum length of an utf-8 multibyte sequence
67#define UTF8_MULTB_MAX 4
68
69typedef std::unordered_map<std::string, std::string> StringMap;
70
71struct FlagDesc {
72 const char *name;
73 u32 flag;
74};
75
76// Try to avoid converting between wide and UTF-8 unless you need to
77// input/output stuff via Irrlicht
78[[nodiscard]] std::wstring utf8_to_wide(std::string_view input);
79[[nodiscard]] std::string wide_to_utf8(std::wstring_view input);
80
81void wide_add_codepoint(std::wstring &result, char32_t codepoint);
82
88size_t utf8_truncate_count(std::string_view input);
89
90std::string urlencode(std::string_view str);
91std::string urldecode(std::string_view str);
92
93u32 readFlagString(std::string str, const FlagDesc *flagdesc, u32 *flagmask);
94std::string writeFlagString(u32 flags, const FlagDesc *flagdesc, u32 flagmask);
95
96size_t mystrlcpy(char *dst, const char *src, size_t size) noexcept;
97
99u64 read_seed(const char *str);
100
101bool parseColorString(const std::string &value, video::SColor &color, bool quiet,
102 unsigned char default_alpha = 0xff);
103std::string encodeHexColorString(video::SColor color);
104
110inline char my_tolower(char c)
111{
112 // By design this function cannot handle any Unicode (codepoints don't fit into char),
113 // but make sure to pass it through unchanged.
114 // tolower() can mangle it if the POSIX locale is not UTF-8.
115 if (static_cast<unsigned char>(c) > 0x7f)
116 return c;
117 // toupper(3): "If the argument c is of type char, it must be cast to unsigned char"
118 return tolower(static_cast<unsigned char>(c));
119}
120
126inline std::string padStringRight(std::string str, size_t len)
127{
128 if (len > str.size())
129 str.insert(str.end(), len - str.size(), ' ');
130
131 return str;
132}
133
145inline std::string_view removeStringEnd(std::string_view str,
146 const char *ends[])
147{
148 const char **p = ends;
149
150 for (; *p && (*p)[0] != '\0'; p++) {
151 std::string_view end(*p);
152 if (str.size() < end.size())
153 continue;
154 if (str.compare(str.size() - end.size(), end.size(), end) == 0)
155 return str.substr(0, str.size() - end.size());
156 }
157
158 return std::string_view();
159}
160
161
162#define MAKE_VARIANT(_name, _t0, _t1) \
163 template <typename T, typename... Args> \
164 inline auto _name(_t0 arg1, _t1 arg2, Args&&... args) \
165 { \
166 return (_name)(std::basic_string_view<T>(arg1), std::basic_string_view<T>(arg2), \
167 std::forward<Args>(args)...); \
168 }
169
170
180template <typename T>
181inline bool str_equal(std::basic_string_view<T> s1,
182 std::basic_string_view<T> s2,
183 bool case_insensitive = false)
184{
185 if (!case_insensitive)
186 return s1 == s2;
187
188 if (s1.size() != s2.size())
189 return false;
190
191 for (size_t i = 0; i < s1.size(); ++i)
192 if (my_tolower(s1[i]) != my_tolower(s2[i]))
193 return false;
194
195 return true;
196}
197
198// For some reason an std::string will not implicitly get converted
199// to an std::basic_string_view<char> in the template case above, so we need
200// these three wrappers. It works if you take out the template parameters.
201// see also <https://stackoverflow.com/questions/68380141/>
202MAKE_VARIANT(str_equal, const std::basic_string<T> &, const std::basic_string<T> &)
203
204MAKE_VARIANT(str_equal, std::basic_string_view<T>, const std::basic_string<T> &)
205
206MAKE_VARIANT(str_equal, const std::basic_string<T> &, std::basic_string_view<T>)
207
208
209
219template <typename T>
220inline bool str_starts_with(std::basic_string_view<T> str,
221 std::basic_string_view<T> prefix,
222 bool case_insensitive = false)
223{
224 if (str.size() < prefix.size())
225 return false;
226
227 if (!case_insensitive)
228 return str.compare(0, prefix.size(), prefix) == 0;
229
230 for (size_t i = 0; i < prefix.size(); ++i)
231 if (my_tolower(str[i]) != my_tolower(prefix[i]))
232 return false;
233 return true;
234}
235
236// (same conversion issue here)
237MAKE_VARIANT(str_starts_with, const std::basic_string<T> &, const std::basic_string<T> &)
238
239MAKE_VARIANT(str_starts_with, std::basic_string_view<T>, const std::basic_string<T> &)
240
241MAKE_VARIANT(str_starts_with, const std::basic_string<T> &, std::basic_string_view<T>)
242
243// (the same but with char pointers, only for the prefix argument)
244MAKE_VARIANT(str_starts_with, const std::basic_string<T> &, const T*)
245
246MAKE_VARIANT(str_starts_with, std::basic_string_view<T>, const T*)
247
248
249
259template <typename T>
260inline bool str_ends_with(std::basic_string_view<T> str,
261 std::basic_string_view<T> suffix,
262 bool case_insensitive = false)
263{
264 if (str.size() < suffix.size())
265 return false;
266
267 size_t start = str.size() - suffix.size();
268 if (!case_insensitive)
269 return str.compare(start, suffix.size(), suffix) == 0;
270
271 for (size_t i = 0; i < suffix.size(); ++i)
272 if (my_tolower(str[start + i]) != my_tolower(suffix[i]))
273 return false;
274 return true;
275}
276
277// (same conversion issue here)
278MAKE_VARIANT(str_ends_with, const std::basic_string<T> &, const std::basic_string<T> &)
279
280MAKE_VARIANT(str_ends_with, std::basic_string_view<T>, const std::basic_string<T> &)
281
282MAKE_VARIANT(str_ends_with, const std::basic_string<T> &, std::basic_string_view<T>)
283
284// (the same but with char pointers, only for the suffix argument)
285MAKE_VARIANT(str_ends_with, const std::basic_string<T> &, const T*)
286
287MAKE_VARIANT(str_ends_with, std::basic_string_view<T>, const T*)
288
289
290#undef MAKE_VARIANT
291
292
299template <typename T>
300[[nodiscard]]
301inline std::vector<std::basic_string<T>> str_split(
302 const std::basic_string<T> &str,
303 T delimiter)
304{
305 std::vector<std::basic_string<T>> parts;
306 std::basic_stringstream<T> sstr(str);
307 std::basic_string<T> part;
308
309 while (std::getline(sstr, part, delimiter))
310 parts.push_back(std::move(part));
311
312 return parts;
313}
314
315
320[[nodiscard]]
321inline std::string lowercase(std::string_view str)
322{
323 std::string s2;
324 s2.resize(str.size());
325 for (size_t i = 0; i < str.size(); i++)
326 s2[i] = my_tolower(str[i]);
327 return s2;
328}
329
330
331inline bool my_isspace(const char c)
332{
333 return std::isspace(static_cast<unsigned char>(c));
334}
335
336inline bool my_isspace(const wchar_t c)
337{
338 return std::iswspace(c);
339}
340
345template<typename T>
346[[nodiscard]]
347inline std::basic_string_view<T> trim(std::basic_string_view<T> str)
348{
349 size_t front = 0;
350 size_t back = str.size();
351
352 while (front < back && my_isspace(str[front]))
353 ++front;
354
355 while (back > front && my_isspace(str[back - 1]))
356 --back;
357
358 return str.substr(front, back - front);
359}
360
361// If input was a temporary string keep it one to make sure patterns like
362// trim(func_that_returns_str()) are predictable regarding memory allocation
363// and don't lead to UAF. ↓ ↓ ↓
364
369template<typename T>
370[[nodiscard]]
371inline std::basic_string<T> trim(std::basic_string<T> &&str)
372{
373 std::basic_string<T> ret(trim(std::basic_string_view<T>(str)));
374 return ret;
375}
376
377template<typename T>
378[[nodiscard]]
379inline std::basic_string_view<T> trim(const std::basic_string<T> &str)
380{
381 return trim(std::basic_string_view<T>(str));
382}
383
384// The above declaration causes ambiguity with char pointers so we have to fix that:
385template<typename T>
386[[nodiscard]]
387inline std::basic_string_view<T> trim(const T *str)
388{
389 return trim(std::basic_string_view<T>(str));
390}
391
392
399inline bool is_yes(std::string_view str)
400{
401 std::string s2 = lowercase(trim(str));
402
403 return s2 == "y" || s2 == "yes" || s2 == "true" || atoi(s2.c_str()) != 0;
404}
405
406
419inline s32 mystoi(const std::string &str, s32 min, s32 max)
420{
421 s32 i = atoi(str.c_str());
422
423 if (i < min)
424 i = min;
425 if (i > max)
426 i = max;
427
428 return i;
429}
430
435inline s32 mystoi(const std::string &str)
436{
437 return atoi(str.c_str());
438}
439
444inline float mystof(const std::string &str)
445{
446 return atof(str.c_str());
447}
448
449#define stoi mystoi
450#define stof mystof
451
453template <typename T>
454inline T from_string(const std::string &str)
455{
456 std::istringstream tmp(str);
457 T t;
458 tmp >> t;
459 return t;
460}
461
463inline s64 stoi64(const std::string &str) { return from_string<s64>(str); }
464
466inline std::string itos(s32 i) { return std::to_string(i); }
468inline std::string i64tos(s64 i) { return std::to_string(i); }
469
471inline std::string ftos(float f)
472{
473 std::ostringstream oss;
474 oss << std::setprecision(std::numeric_limits<float>::max_digits10) << f;
475 return oss.str();
476}
477
479std::string my_double_to_string(double number);
481std::optional<double> my_string_to_double(const std::string &s);
482
490inline void str_replace(std::string &str, std::string_view pattern,
491 std::string_view replacement)
492{
493 std::string::size_type start = str.find(pattern, 0);
494 while (start != str.npos) {
495 str.replace(start, pattern.size(), replacement);
496 start = str.find(pattern, start + replacement.size());
497 }
498}
499
503inline void str_formspec_escape(std::string &str)
504{
505 str_replace(str, "\\", "\\\\");
506 str_replace(str, "]", "\\]");
507 str_replace(str, "[", "\\[");
508 str_replace(str, ";", "\\;");
509 str_replace(str, ",", "\\,");
510 str_replace(str, "$", "\\$");
511}
512
516inline void str_texture_modifiers_escape(std::string &str)
517{
518 str_replace(str, "\\", "\\\\");
519 str_replace(str, "^", "\\^");
520 str_replace(str, ":", "\\:");
521}
522
530void str_replace(std::string &str, char from, char to);
531
532
543inline bool string_allowed(std::string_view str, std::string_view allowed_chars)
544{
545 return str.find_first_not_of(allowed_chars) == str.npos;
546}
547
548
559inline bool string_allowed_blacklist(std::string_view str,
560 std::string_view blacklisted_chars)
561{
562 return str.find_first_of(blacklisted_chars) == str.npos;
563}
564
565
582std::string wrap_rows(std::string_view from, unsigned row_len, bool has_color_codes = false);
583
584
588template <typename T>
589[[nodiscard]]
590std::basic_string<T> unescape_string(std::basic_string_view<T> str, const T esc = T('\\'))
591{
592 std::basic_string<T> out;
593 size_t pos = 0;
594 out.reserve(str.size());
595 while (pos < str.size()) {
596 size_t cpos = str.find(esc, pos); // find next escape
597 if (cpos == std::string::npos) {
598 out += str.substr(pos);
599 break;
600 }
601 out += str.substr(pos, cpos - pos); // preceding part
602 if (cpos + 1 != str.size())
603 out += str[cpos + 1]; // the char after
604 pos = cpos + 2;
605 }
606 return out;
607}
608
609// (same templating issue here)
610[[nodiscard]]
611inline std::string unescape_string(std::string_view s, const char esc = '\\')
612{
613 return unescape_string<char>(s, esc);
614}
615[[nodiscard]]
616inline std::wstring unescape_string(std::wstring_view s, const wchar_t esc = L'\\')
617{
618 return unescape_string<wchar_t>(s, esc);
619}
620
621
628template <typename T>
629[[nodiscard]]
630std::basic_string<T> unescape_enriched(std::basic_string_view<T> s)
631{
632 std::basic_string<T> output;
633 output.reserve(s.size());
634 size_t i = 0;
635 while (i < s.length()) {
636 if (s[i] == static_cast<T>('\x1b')) {
637 ++i;
638 if (i == s.length())
639 continue;
640 if (s[i] == static_cast<T>('(')) {
641 ++i;
642 while (i < s.length() && s[i] != static_cast<T>(')')) {
643 if (s[i] == static_cast<T>('\\'))
644 ++i;
645 ++i;
646 }
647 }
648 ++i;
649 continue;
650 }
651 output += s[i];
652 ++i;
653 }
654 return output;
655}
656
657// (same templating issue here)
658[[nodiscard]]
659inline std::string unescape_enriched(std::string_view s)
660{
661 return unescape_enriched<char>(s);
662}
663[[nodiscard]]
664inline std::wstring unescape_enriched(std::wstring_view s)
665{
667}
668
676template <typename T>
677[[nodiscard]]
678std::vector<std::basic_string<T>> split(std::basic_string_view<T> s,
679 T delim, T escape = static_cast<T>('\\'))
680{
681 std::vector<std::basic_string<T>> tokens;
682
683 std::basic_string<T> current;
684 bool last_was_escape = false;
685 for (size_t i = 0; i < s.length(); i++) {
686 T si = s[i];
687 if (last_was_escape) {
688 current += escape;
689 current += si;
690 last_was_escape = false;
691 } else {
692 if (si == delim) {
693 tokens.emplace_back(std::move(current));
694 current.clear();
695 last_was_escape = false;
696 } else if (si == escape) {
697 last_was_escape = true;
698 } else {
699 current += si;
700 last_was_escape = false;
701 }
702 }
703 }
704 // push last element
705 tokens.emplace_back(std::move(current));
706
707 return tokens;
708}
709
710template <typename T>
711[[nodiscard]]
712std::vector<std::basic_string<T>> split(const std::basic_string<T> &s,
713 T delim, T escape = static_cast<T>('\\'))
714{
715 return split(std::basic_string_view<T>(s), delim, escape);
716}
717
718[[nodiscard]]
719std::wstring translate_string(std::wstring_view s, Translations *translations);
720
721[[nodiscard]]
722std::wstring translate_string(std::wstring_view s);
723
724[[nodiscard]]
725inline std::wstring unescape_translate(std::wstring_view s)
726{
728}
729
737inline bool is_number(std::string_view to_check)
738{
739 for (char c : to_check)
740 if (!isdigit(static_cast<unsigned char>(c)))
741 return false;
742
743 return !to_check.empty();
744}
745
746
752inline const char *bool_to_cstr(bool val)
753{
754 return val ? "true" : "false";
755}
756
764inline const std::string duration_to_string(int sec)
765{
766 std::ostringstream ss;
767 const char *neg = "";
768 if (sec < 0) {
769 sec = -sec;
770 neg = "-";
771 }
772 int total_sec = sec;
773 int min = sec / 60;
774 sec %= 60;
775 int hour = min / 60;
776 min %= 60;
777 int day = hour / 24;
778 hour %= 24;
779
780 if (day > 0) {
781 ss << neg << day << "d";
782 if (hour > 0 || min > 0 || sec > 0)
783 ss << " ";
784 }
785
786 if (hour > 0) {
787 ss << neg << hour << "h";
788 if (min > 0 || sec > 0)
789 ss << " ";
790 }
791
792 if (min > 0) {
793 ss << neg << min << "min";
794 if (sec > 0)
795 ss << " ";
796 }
797
798 if (sec > 0 || total_sec == 0) {
799 ss << neg << sec << "s";
800 }
801
802 return ss.str();
803}
804
810[[nodiscard]]
811inline std::string str_join(const std::vector<std::string> &list,
812 std::string_view delimiter)
813{
814 std::string ret;
815 bool first = true;
816 for (const auto &part : list) {
817 if (!first)
818 ret.append(delimiter);
819 ret.append(part);
820 first = false;
821 }
822 return ret;
823}
824
825#if IS_CLIENT_BUILD
829[[nodiscard]]
830inline std::string stringw_to_utf8(const core::stringw &input)
831{
832 std::wstring_view sv(input.c_str(), input.size());
833 return wide_to_utf8(sv);
834}
835
839[[nodiscard]]
840inline core::stringw utf8_to_stringw(std::string_view input)
841{
842 std::wstring str = utf8_to_wide(input);
843 return core::stringw(std::move(str));
844}
845#endif
846
853[[nodiscard]]
854std::string sanitizeDirName(std::string_view str, std::string_view optional_prefix);
855
863[[nodiscard]]
864std::string sanitize_untrusted(std::string_view str, bool keep_escapes = true);
865
872void safe_print_string(std::ostream &os, std::string_view str);
873
880std::optional<v3f> str_to_v3f(std::string_view str);
Definition translation.h:19
std::optional< v3f > str_to_v3f(std::string_view str)
Parses a string of form (1, 2, 3) or 1, 2, 4 to a v3f.
Definition string.cpp:1051
bool my_isspace(const char c)
Definition string.h:331
s64 stoi64(const std::string &str)
Returns a 64-bit signed value represented by the string str (decimal).
Definition string.h:463
std::string writeFlagString(u32 flags, const FlagDesc *flagdesc, u32 flagmask)
Definition string.cpp:281
bool string_allowed(std::string_view str, std::string_view allowed_chars)
Check that a string only contains whitelisted characters.
Definition string.h:543
std::string wide_to_utf8(std::wstring_view input)
Definition string.cpp:115
std::string my_double_to_string(double number)
Converts double to string. Handles high precision and inf/nan.
Definition string.cpp:1090
bool str_equal(std::basic_string_view< T > s1, std::basic_string_view< T > s2, bool case_insensitive=false)
Check two strings for equivalence.
Definition string.h:181
std::string sanitize_untrusted(std::string_view str, bool keep_escapes=true)
Sanitize an untrusted string (e.g.
Definition string.cpp:1001
u32 readFlagString(std::string str, const FlagDesc *flagdesc, u32 *flagmask)
Definition string.cpp:245
std::optional< double > my_string_to_double(const std::string &s)
Converts string to double. Handles high precision and inf/nan.
Definition string.cpp:1104
std::wstring unescape_translate(std::wstring_view s)
Definition string.h:725
void wide_add_codepoint(std::wstring &result, char32_t codepoint)
Definition string.cpp:170
const std::string duration_to_string(int sec)
Converts a duration in seconds to a pretty-printed duration in days, hours, minutes and seconds.
Definition string.h:764
const char * bool_to_cstr(bool val)
Returns a C-string, either "true" or "false", corresponding to val.
Definition string.h:752
std::wstring translate_string(std::wstring_view s, Translations *translations)
Definition string.cpp:892
char my_tolower(char c)
Converts a letter to lowercase, with safe handling of the char type and non-ASCII.
Definition string.h:110
size_t utf8_truncate_count(std::string_view input)
Takes a string that may end with a truncated UTF-8 sequence and gets rid of the incomplete sequence.
Definition string.cpp:187
std::string wrap_rows(std::string_view from, unsigned row_len, bool has_color_codes=false)
Create a string based on from where a newline is forcefully inserted every row_len characters.
Definition string.cpp:614
bool parseColorString(const std::string &value, video::SColor &color, bool quiet, unsigned char default_alpha=0xff)
Definition string.cpp:579
std::basic_string< T > unescape_string(std::basic_string_view< T > str, const T esc=T('\\'))
Unescapes a string.
Definition string.h:590
void str_replace(std::string &str, std::string_view pattern, std::string_view replacement)
Replace all occurrences of pattern in str with replacement.
Definition string.h:490
T from_string(const std::string &str)
Returns a value represented by the string val.
Definition string.h:454
std::vector< std::basic_string< T > > str_split(const std::basic_string< T > &str, T delimiter)
Splits a string into its component parts separated by the character delimiter.
Definition string.h:301
std::string sanitizeDirName(std::string_view str, std::string_view optional_prefix)
Sanitize the name of a new directory.
Definition string.cpp:948
std::unordered_map< std::string, std::string > StringMap
Definition string.h:69
bool str_ends_with(std::basic_string_view< T > str, std::basic_string_view< T > suffix, bool case_insensitive=false)
Check whether str ends with the string suffix.
Definition string.h:260
std::string urlencode(std::string_view str)
Definition string.cpp:207
bool string_allowed_blacklist(std::string_view str, std::string_view blacklisted_chars)
Check that a string contains no blacklisted characters.
Definition string.h:559
size_t mystrlcpy(char *dst, const char *src, size_t size) noexcept
Definition string.cpp:302
std::string str_join(const std::vector< std::string > &list, std::string_view delimiter)
Joins a vector of strings by the string delimiter.
Definition string.h:811
void str_texture_modifiers_escape(std::string &str)
Escapes characters to nest texture modifiers.
Definition string.h:516
std::string urldecode(std::string_view str)
Definition string.cpp:226
std::string padStringRight(std::string str, size_t len)
Returns a copy of str with spaces inserted at the right hand side to ensure that the string is len ch...
Definition string.h:126
std::vector< std::basic_string< T > > split(std::basic_string_view< T > s, T delim, T escape=static_cast< T >('\\'))
Splits a string into its component parts separated by the character delimiter.
Definition string.h:678
bool str_starts_with(std::basic_string_view< T > str, std::basic_string_view< T > prefix, bool case_insensitive=false)
Check whether str begins with the string prefix.
Definition string.h:220
float mystof(const std::string &str)
Returns a float reprensented by the string str (decimal).
Definition string.h:444
std::string itos(s32 i)
Returns a string representing the decimal value of the 32-bit value i.
Definition string.h:466
void str_formspec_escape(std::string &str)
Escapes characters that cannot be used in formspecs.
Definition string.h:503
void safe_print_string(std::ostream &os, std::string_view str)
Prints a sanitized version of a string without control characters.
Definition string.cpp:1036
std::string i64tos(s64 i)
Returns a string representing the decimal value of the 64-bit value i.
Definition string.h:468
std::string lowercase(std::string_view str)
Definition string.h:321
std::string ftos(float f)
Returns a string representing the exact decimal value of the float value f.
Definition string.h:471
std::string_view removeStringEnd(std::string_view str, const char *ends[])
Returns a version of str with the first occurrence of a string contained within ends[] removed from t...
Definition string.h:145
std::string encodeHexColorString(video::SColor color)
Definition string.cpp:595
#define MAKE_VARIANT(_name, _t0, _t1)
Definition string.h:162
std::wstring utf8_to_wide(std::string_view input)
Definition string.cpp:87
bool is_yes(std::string_view str)
Returns whether str should be regarded as (bool) true.
Definition string.h:399
std::basic_string< T > unescape_enriched(std::basic_string_view< T > s)
Remove all escape sequences in s.
Definition string.h:630
u64 read_seed(const char *str)
turn string into a map seed. either directly if it's a number or by hashing it.
Definition string.cpp:315
bool is_number(std::string_view to_check)
Checks that all characters in to_check are decimal digits.
Definition string.h:737
std::basic_string_view< T > trim(std::basic_string_view< T > str)
Definition string.h:347
s32 mystoi(const std::string &str, s32 min, s32 max)
Converts the string str to a signed 32-bit integer.
Definition string.h:419
Definition string.h:71
u32 flag
Definition string.h:73
const char * name
Definition string.h:72
static std::string p(std::string path)
Definition test_filesys.cpp:69