From d3ec4a47ddb307b340ecfc3fb143797ade1c4375 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Thu, 18 Mar 2021 23:56:16 +0100 Subject: [PATCH] ditch cs_string from public headers + style fix --- include/cubescript/cubescript.hh | 6 ++---- include/cubescript/cubescript_conf.hh | 6 +++--- src/cs_util.hh | 2 ++ src/lib_str.cc | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 4ef36f0..0c02c78 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -19,8 +19,6 @@ namespace cscript { -using cs_string = std::string; - static_assert(std::is_integral_v, "cs_int must be integral"); static_assert(std::is_signed_v, "cs_int must be signed"); static_assert(std::is_floating_point_v, "cs_float must be floating point"); @@ -761,7 +759,7 @@ namespace util { template inline void format_int(R &&writer, cs_int val) { try { - ostd::format(std::forward(writer), IntFormat, val); + ostd::format(std::forward(writer), CS_INT_FORMAT, val); } catch (ostd::format_error const &e) { throw cs_internal_error{e.what()}; } @@ -772,7 +770,7 @@ namespace util { try { ostd::format( std::forward(writer), - (val == cs_int(val)) ? RoundFloatFormat : FloatFormat, val + (val == floor(val)) ? CS_ROUND_FLOAT_FORMAT : CS_FLOAT_FORMAT, val ); } catch (ostd::format_error const &e) { throw cs_internal_error{e.what()}; diff --git a/include/cubescript/cubescript_conf.hh b/include/cubescript/cubescript_conf.hh index 2822447..dd6dcc5 100644 --- a/include/cubescript/cubescript_conf.hh +++ b/include/cubescript/cubescript_conf.hh @@ -37,9 +37,9 @@ namespace cscript { using cs_hook_cb = std::function; using cs_alloc_cb = void *(*)(void *, void *, size_t, size_t); - constexpr auto const IntFormat = "%d"; - constexpr auto const FloatFormat = "%.7g"; - constexpr auto const RoundFloatFormat = "%.1f"; + constexpr auto const CS_INT_FORMAT = "%d"; + constexpr auto const CS_FLOAT_FORMAT = "%.7g"; + constexpr auto const CS_ROUND_FLOAT_FORMAT = "%.1f"; } /* namespace cscript */ #endif /* LIBCUBESCRIPT_CUBESCRIPT_CONF_HH */ \ No newline at end of file diff --git a/src/cs_util.hh b/src/cs_util.hh index ae3a9a7..e773834 100644 --- a/src/cs_util.hh +++ b/src/cs_util.hh @@ -14,6 +14,8 @@ using cs_map = std::unordered_map; template using cs_vector = std::vector; +using cs_string = std::string; + cs_int cs_parse_int( ostd::string_range input, ostd::string_range *end = nullptr ); diff --git a/src/lib_str.cc b/src/lib_str.cc index 1b0194c..acbd3ce 100644 --- a/src/lib_str.cc +++ b/src/lib_str.cc @@ -2,6 +2,8 @@ #include +#include "cs_util.hh" + namespace cscript { template