diff options
| -rw-r--r-- | src/common/string_util.cpp | 40 | ||||
| -rw-r--r-- | src/common/string_util.h | 17 |
2 files changed, 3 insertions, 54 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 731d1db34..5b004ef48 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -4,11 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <cctype> | 6 | #include <cctype> |
| 7 | #include <cerrno> | ||
| 8 | #include <codecvt> | 7 | #include <codecvt> |
| 9 | #include <cstdio> | ||
| 10 | #include <cstdlib> | 8 | #include <cstdlib> |
| 11 | #include <cstring> | 9 | #include <iomanip> |
| 10 | #include <locale> | ||
| 11 | #include <sstream> | ||
| 12 | #include "common/common_paths.h" | 12 | #include "common/common_paths.h" |
| 13 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 14 | #include "common/string_util.h" | 14 | #include "common/string_util.h" |
| @@ -75,40 +75,6 @@ std::string StripQuotes(const std::string& s) { | |||
| 75 | return s; | 75 | return s; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | bool TryParse(const std::string& str, u32* const output) { | ||
| 79 | char* endptr = nullptr; | ||
| 80 | |||
| 81 | // Reset errno to a value other than ERANGE | ||
| 82 | errno = 0; | ||
| 83 | |||
| 84 | unsigned long value = strtoul(str.c_str(), &endptr, 0); | ||
| 85 | |||
| 86 | if (!endptr || *endptr) | ||
| 87 | return false; | ||
| 88 | |||
| 89 | if (errno == ERANGE) | ||
| 90 | return false; | ||
| 91 | |||
| 92 | #if ULONG_MAX > UINT_MAX | ||
| 93 | if (value >= 0x100000000ull && value <= 0xFFFFFFFF00000000ull) | ||
| 94 | return false; | ||
| 95 | #endif | ||
| 96 | |||
| 97 | *output = static_cast<u32>(value); | ||
| 98 | return true; | ||
| 99 | } | ||
| 100 | |||
| 101 | bool TryParse(const std::string& str, bool* const output) { | ||
| 102 | if ("1" == str || "true" == ToLower(str)) | ||
| 103 | *output = true; | ||
| 104 | else if ("0" == str || "false" == ToLower(str)) | ||
| 105 | *output = false; | ||
| 106 | else | ||
| 107 | return false; | ||
| 108 | |||
| 109 | return true; | ||
| 110 | } | ||
| 111 | |||
| 112 | std::string StringFromBool(bool value) { | 78 | std::string StringFromBool(bool value) { |
| 113 | return value ? "True" : "False"; | 79 | return value ? "True" : "False"; |
| 114 | } | 80 | } |
diff --git a/src/common/string_util.h b/src/common/string_util.h index f76fc43dc..7e32d6405 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -5,8 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <iomanip> | ||
| 9 | #include <sstream> | ||
| 10 | #include <string> | 8 | #include <string> |
| 11 | #include <vector> | 9 | #include <vector> |
| 12 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| @@ -28,21 +26,6 @@ std::string StripQuotes(const std::string& s); | |||
| 28 | 26 | ||
| 29 | std::string StringFromBool(bool value); | 27 | std::string StringFromBool(bool value); |
| 30 | 28 | ||
| 31 | bool TryParse(const std::string& str, bool* output); | ||
| 32 | bool TryParse(const std::string& str, u32* output); | ||
| 33 | |||
| 34 | template <typename N> | ||
| 35 | static bool TryParse(const std::string& str, N* const output) { | ||
| 36 | std::istringstream iss(str); | ||
| 37 | |||
| 38 | N tmp = 0; | ||
| 39 | if (iss >> tmp) { | ||
| 40 | *output = tmp; | ||
| 41 | return true; | ||
| 42 | } else | ||
| 43 | return false; | ||
| 44 | } | ||
| 45 | |||
| 46 | std::string TabsToSpaces(int tab_size, std::string in); | 29 | std::string TabsToSpaces(int tab_size, std::string in); |
| 47 | 30 | ||
| 48 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); | 31 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); |