summaryrefslogtreecommitdiffstats
path: root/core/config/number.hh
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-11 13:48:31 +0500
committeruntodesu <kirill@untode.su>2025-09-11 13:48:31 +0500
commitaaed751bf4430bf4b9b30cef532b8753b9f639ce (patch)
tree16bc751c272ba27ad53ec48dbdd3a6d9e6a8d4c2 /core/config/number.hh
parent96bd73ae020ecca1f94698744c77498a89ad19f7 (diff)
downloadvoxelius-aaed751bf4430bf4b9b30cef532b8753b9f639ce.tar.bz2
voxelius-aaed751bf4430bf4b9b30cef532b8753b9f639ce.zip
Replace most of C strings with string_view
Diffstat (limited to 'core/config/number.hh')
-rw-r--r--core/config/number.hh20
1 files changed, 12 insertions, 8 deletions
diff --git a/core/config/number.hh b/core/config/number.hh
index 9907993..ad79770 100644
--- a/core/config/number.hh
+++ b/core/config/number.hh
@@ -14,8 +14,8 @@ public:
explicit Number(T default_value, T min_value, T max_value);
virtual ~Number(void) = default;
- virtual void set(const char* value) override;
- virtual const char* get(void) const override;
+ virtual void set(std::string_view value) override;
+ virtual std::string_view get(void) const override;
T get_value(void) const;
void set_value(T value);
@@ -79,17 +79,21 @@ inline config::Number<T>::Number(T default_value, T min_value, T max_value)
}
template<math::Arithmetic T>
-inline void config::Number<T>::set(const char* value)
+inline void config::Number<T>::set(std::string_view value)
{
- std::istringstream(value) >> m_value;
- m_value = std::clamp(m_value, m_min_value, m_max_value);
- m_string = std::to_string(m_value);
+ T parsed_value;
+ auto result = std::from_chars(value.data(), value.data() + value.size(), parsed_value);
+
+ if(result.ec == std::errc()) {
+ m_value = std::clamp(parsed_value, m_min_value, m_max_value);
+ m_string = std::to_string(m_value);
+ }
}
template<math::Arithmetic T>
-inline const char* config::Number<T>::get(void) const
+inline std::string_view config::Number<T>::get(void) const
{
- return m_string.c_str();
+ return m_string;
}
template<math::Arithmetic T>