From af1a85fb91cdbd80914fab44e6cda9b286a8e20c Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 19 Mar 2021 00:34:12 +0100 Subject: [PATCH] get rid of public format_int/float (use cs_value) --- include/cubescript/cubescript.hh | 21 --------------------- src/cs_val.cc | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 95aa10f..d48b285 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -760,27 +760,6 @@ namespace util { cs_state &cs, ostd::string_range str ); - template - inline void format_int(R &&writer, cs_int val) { - try { - ostd::format(std::forward(writer), CS_INT_FORMAT, val); - } catch (ostd::format_error const &e) { - throw cs_internal_error{e.what()}; - } - } - - template - inline void format_float(R &&writer, cs_float val) { - try { - ostd::format( - std::forward(writer), - (val == floor(val)) ? CS_ROUND_FLOAT_FORMAT : CS_FLOAT_FORMAT, val - ); - } catch (ostd::format_error const &e) { - throw cs_internal_error{e.what()}; - } - } - template inline void print_stack(R &&writer, cs_stack_state const &st) { auto nd = st.get(); diff --git a/src/cs_val.cc b/src/cs_val.cc index a9d20b7..78c7264 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -6,13 +6,23 @@ namespace cscript { static cs_string intstr(cs_int v) { auto app = ostd::appender(); - cscript::util::format_int(app, v); + try { + ostd::format(app, CS_INT_FORMAT, v); + } catch (ostd::format_error const &e) { + throw cs_internal_error{e.what()}; + } return std::move(app.get()); } static cs_string floatstr(cs_float v) { auto app = ostd::appender(); - cscript::util::format_float(app, v); + try { + ostd::format( + app, (v == floor(v)) ? CS_ROUND_FLOAT_FORMAT : CS_FLOAT_FORMAT, v + ); + } catch (ostd::format_error const &e) { + throw cs_internal_error{e.what()}; + } return std::move(app.get()); }