25#ifndef TGUI_STRING_VIEW_HPP
26#define TGUI_STRING_VIEW_HPP
28#include <TGUI/Config.hpp>
39 inline namespace literals
41 inline namespace string_view_literals
45 using namespace std::literals::string_view_literals;
49 using StringView = std::u32string_view;
50 using CharStringView = std::string_view;
62 return std::equal(view1.begin(),
66 [](
char char1,
char char2)
70 return std::tolower(static_cast<unsigned char>(char1))
71 == std::tolower(static_cast<unsigned char>(char2));
85 return std::equal(view1.cbegin(),
89 [](
char32_t char1,
char32_t char2)
93 if ((char1 < 128) && (char2 < 128))
94 return std::tolower(static_cast<unsigned char>(char1))
95 == std::tolower(static_cast<unsigned char>(char2));
100#if defined(__cpp_lib_starts_ends_with) && (__cpp_lib_starts_ends_with >= 201711L)
109 [[nodiscard]]
inline bool viewStartsWith(CharStringView viewToLookInto, CharStringView viewToLookFor)
111 return viewToLookInto.starts_with(viewToLookFor);
122 [[nodiscard]]
inline bool viewStartsWith(CharStringView viewToLookInto,
char charToLookFor)
124 return viewToLookInto.starts_with(charToLookFor);
135 [[nodiscard]]
inline bool viewEndsWith(CharStringView viewToLookInto, CharStringView viewToLookFor)
137 return viewToLookInto.ends_with(viewToLookFor);
148 [[nodiscard]]
inline bool viewEndsWith(CharStringView viewToLookInto,
char charToLookFor)
150 return viewToLookInto.ends_with(charToLookFor);
161 [[nodiscard]]
inline bool viewStartsWith(StringView viewToLookInto, StringView viewToLookFor)
163 return viewToLookInto.starts_with(viewToLookFor);
174 [[nodiscard]]
inline bool viewStartsWith(StringView viewToLookInto,
char32_t charToLookFor)
176 return viewToLookInto.starts_with(charToLookFor);
187 [[nodiscard]]
inline bool viewEndsWith(StringView viewToLookInto, StringView viewToLookFor)
189 return viewToLookInto.ends_with(viewToLookFor);
200 [[nodiscard]]
inline bool viewEndsWith(StringView viewToLookInto,
char32_t charToLookFor)
202 return viewToLookInto.ends_with(charToLookFor);
213 [[nodiscard]]
inline bool viewStartsWith(CharStringView viewToLookInto, CharStringView viewToLookFor)
215 if (viewToLookFor.length() > viewToLookInto.length())
218 return viewToLookInto.substr(0, viewToLookFor.length()) == viewToLookFor;
229 [[nodiscard]]
inline bool viewStartsWith(CharStringView viewToLookInto,
char charToLookFor)
231 return !viewToLookInto.empty() && (viewToLookInto.front() == charToLookFor);
242 [[nodiscard]]
inline bool viewEndsWith(CharStringView viewToLookInto, CharStringView viewToLookFor)
244 if (viewToLookFor.length() > viewToLookInto.length())
247 return CharStringView(viewToLookInto.data() + (viewToLookInto.length() - viewToLookFor.length()), viewToLookFor.length())
248 .compare(viewToLookFor)
260 [[nodiscard]]
inline bool viewEndsWith(CharStringView viewToLookInto,
char charToLookFor)
262 return !viewToLookInto.empty() && (viewToLookInto.back() == charToLookFor);
273 [[nodiscard]]
inline bool viewStartsWith(StringView viewToLookInto, StringView viewToLookFor)
275 if (viewToLookFor.length() > viewToLookInto.length())
278 return viewToLookInto.substr(0, viewToLookFor.length()) == viewToLookFor;
289 [[nodiscard]]
inline bool viewStartsWith(StringView viewToLookInto,
char32_t charToLookFor)
291 return !viewToLookInto.empty() && (viewToLookInto.front() == charToLookFor);
302 [[nodiscard]]
inline bool viewEndsWith(StringView viewToLookInto, StringView viewToLookFor)
304 if (viewToLookFor.length() > viewToLookInto.length())
307 return StringView(viewToLookInto.data() + (viewToLookInto.length() - viewToLookFor.length()), viewToLookFor.length())
308 .compare(viewToLookFor)
320 [[nodiscard]]
inline bool viewEndsWith(StringView viewToLookInto,
char32_t charToLookFor)
322 return !viewToLookInto.empty() && (viewToLookInto.back() == charToLookFor);
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
bool viewStartsWith(CharStringView viewToLookInto, CharStringView viewToLookFor)
Checks whether the view starts with the given substring.
Definition StringView.hpp:213
bool viewEqualIgnoreCase(CharStringView view1, CharStringView view2)
Returns whether two view are equal if letters would have been lowercase.
Definition StringView.hpp:60
bool viewEndsWith(CharStringView viewToLookInto, CharStringView viewToLookFor)
Checks whether the view ends with the given substring.
Definition StringView.hpp:242