diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-09-22 16:24:20 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-09-22 16:24:20 +1000 |
commit | 3e8f914154b06af319ea7fffa633e0501f0e1f62 (patch) | |
tree | eefcb2f922c46214e88bd9c6de2c5f0736cc45b7 /source/core/StarLexicalCast.cpp | |
parent | ca48a137ec25f1002af4a1ab6e6e5047b5684ca6 (diff) |
fix bool lexical casts
oops
Diffstat (limited to 'source/core/StarLexicalCast.cpp')
-rw-r--r-- | source/core/StarLexicalCast.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/core/StarLexicalCast.cpp b/source/core/StarLexicalCast.cpp index 1387b2e..e607ee5 100644 --- a/source/core/StarLexicalCast.cpp +++ b/source/core/StarLexicalCast.cpp @@ -10,4 +10,27 @@ void throwLexicalCastError(std::errc ec, const char* first, const char* last) { throw BadLexicalCast(strf("Lexical cast failed on '{}'", str)); } +template <> +bool tryLexicalCast(bool& result, const char* first, const char* last) { + size_t len = last - first; + if (strncmp(first, "true", len) == 0) + result = true; + else if (strncmp(first, "false", len) != 0) + return false; + + result = false; + return true; +} + +template <> +bool lexicalCast(const char* first, const char* last) { + size_t len = last - first; + if (strncmp(first, "true", len) == 0) + return true; + else if (strncmp(first, "false", len) != 0) + throwLexicalCastError(std::errc(), first, last); + + return false; +} + }
\ No newline at end of file |