Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarLexicalCast.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-26 01:42:18 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-26 01:42:18 +1000
commit09d26d43b5262f480fd55eab9980eff06a71edbb (patch)
tree1e53765861cd966d204782aeefd15b1a67b3266f /source/core/StarLexicalCast.hpp
parent13a74602bd4c46149da9949d448387a40b8ebd1c (diff)
Add string view variant of Star::String and use it
it's 1:30 AM AGAIN !! !!!!! This might have broken the inventory icons of custom hats a little, need to look into that
Diffstat (limited to 'source/core/StarLexicalCast.hpp')
-rw-r--r--source/core/StarLexicalCast.hpp29
1 files changed, 5 insertions, 24 deletions
diff --git a/source/core/StarLexicalCast.hpp b/source/core/StarLexicalCast.hpp
index 6e6c66e..2831f95 100644
--- a/source/core/StarLexicalCast.hpp
+++ b/source/core/StarLexicalCast.hpp
@@ -2,6 +2,7 @@
#define STAR_LEXICAL_CAST_HPP
#include "StarString.hpp"
+#include "StarStringView.hpp"
#include "StarMaybe.hpp"
#include <sstream>
@@ -14,9 +15,9 @@ STAR_EXCEPTION(BadLexicalCast, StarException);
// Very simple basic lexical cast using stream input. Always operates in the
// "C" locale.
template <typename Type>
-Maybe<Type> maybeLexicalCast(std::string const& s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
+Maybe<Type> maybeLexicalCast(StringView s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
Type result;
- std::istringstream stream(s);
+ std::istringstream stream(std::string(s.utf8()));
stream.flags(flags);
stream.imbue(std::locale::classic());
@@ -28,21 +29,11 @@ Maybe<Type> maybeLexicalCast(std::string const& s, std::ios_base::fmtflags flags
if (stream >> ch)
return {};
- return result;
+ return move(result);
}
template <typename Type>
-Maybe<Type> maybeLexicalCast(char const* s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
- return maybeLexicalCast<Type>(std::string(s), flags);
-}
-
-template <typename Type>
-Maybe<Type> maybeLexicalCast(String const& s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
- return maybeLexicalCast<Type>(s.utf8(), flags);
-}
-
-template <typename Type>
-Type lexicalCast(std::string const& s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
+Type lexicalCast(StringView s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
auto m = maybeLexicalCast<Type>(s, flags);
if (m)
return m.take();
@@ -50,16 +41,6 @@ Type lexicalCast(std::string const& s, std::ios_base::fmtflags flags = std::ios_
throw BadLexicalCast(strf("Lexical cast failed on '%s'", s));
}
-template <typename Type>
-Type lexicalCast(char const* s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
- return lexicalCast<Type>(std::string(s), flags);
-}
-
-template <typename Type>
-Type lexicalCast(String const& s, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
- return lexicalCast<Type>(s.utf8(), flags);
-}
-
template <class Type>
std::string toString(Type const& t, std::ios_base::fmtflags flags = std::ios_base::boolalpha) {
std::stringstream ss;