66#include < cstring>
77#include < clocale>
88#include < charconv>
9+ #include < tuple>
910
1011namespace BT
1112{
@@ -46,31 +47,28 @@ std::string toStr(NodeStatus status, bool colored)
4647 {
4748 return toStr (status);
4849 }
49- else
50+ switch (status)
5051 {
51- switch (status)
52- {
53- case NodeStatus::SUCCESS :
54- return " \x1b [32m"
55- " SUCCESS"
56- " \x1b [0m" ; // RED
57- case NodeStatus::FAILURE :
58- return " \x1b [31m"
59- " FAILURE"
60- " \x1b [0m" ; // GREEN
61- case NodeStatus::RUNNING :
62- return " \x1b [33m"
63- " RUNNING"
64- " \x1b [0m" ; // YELLOW
65- case NodeStatus::SKIPPED :
66- return " \x1b [34m"
67- " SKIPPED"
68- " \x1b [0m" ; // BLUE
69- case NodeStatus::IDLE :
70- return " \x1b [36m"
71- " IDLE"
72- " \x1b [0m" ; // CYAN
73- }
52+ case NodeStatus::SUCCESS :
53+ return " \x1b [32m"
54+ " SUCCESS"
55+ " \x1b [0m" ; // RED
56+ case NodeStatus::FAILURE :
57+ return " \x1b [31m"
58+ " FAILURE"
59+ " \x1b [0m" ; // GREEN
60+ case NodeStatus::RUNNING :
61+ return " \x1b [33m"
62+ " RUNNING"
63+ " \x1b [0m" ; // YELLOW
64+ case NodeStatus::SKIPPED :
65+ return " \x1b [34m"
66+ " SKIPPED"
67+ " \x1b [0m" ; // BLUE
68+ case NodeStatus::IDLE :
69+ return " \x1b [36m"
70+ " IDLE"
71+ " \x1b [0m" ; // CYAN
7472 }
7573 return " Undefined" ;
7674}
@@ -120,7 +118,8 @@ template <>
120118int64_t convertFromString<int64_t >(StringView str)
121119{
122120 long result = 0 ;
123- auto [ptr, ec] = std::from_chars (str.data (), str.data () + str.size (), result);
121+ const auto [ptr, ec] = std::from_chars (str.data (), str.data () + str.size (), result);
122+ std::ignore = ptr;
124123 if (ec != std::errc ())
125124 {
126125 throw RuntimeError (StrCat (" Can't convert string [" , str, " ] to integer" ));
@@ -132,7 +131,8 @@ template <>
132131uint64_t convertFromString<uint64_t >(StringView str)
133132{
134133 unsigned long result = 0 ;
135- auto [ptr, ec] = std::from_chars (str.data (), str.data () + str.size (), result);
134+ const auto [ptr, ec] = std::from_chars (str.data (), str.data () + str.size (), result);
135+ std::ignore = ptr;
136136 if (ec != std::errc ())
137137 {
138138 throw RuntimeError (StrCat (" Can't convert string [" , str, " ] to integer" ));
@@ -194,21 +194,23 @@ double convertFromString<double>(StringView str)
194194 // see issue #120
195195 // http://quick-bench.com/DWaXRWnxtxvwIMvZy2DxVPEKJnE
196196
197- std::string old_locale = setlocale (LC_NUMERIC , nullptr );
198- setlocale (LC_NUMERIC , " C" );
199- double val = std::stod (str.data ());
200- setlocale (LC_NUMERIC , old_locale.c_str ());
197+ const std::string old_locale = setlocale (LC_NUMERIC , nullptr );
198+ std::ignore = setlocale (LC_NUMERIC , " C" );
199+ const std::string str_copy (str.data (), str.size ());
200+ const double val = std::stod (str_copy);
201+ std::ignore = setlocale (LC_NUMERIC , old_locale.c_str ());
201202 return val;
202203}
203204
204205template <>
205206float convertFromString<float >(StringView str)
206207{
207- std::string old_locale = setlocale (LC_NUMERIC , nullptr );
208- setlocale (LC_NUMERIC , " C" );
209- float val = std::stof (str.data ());
210- setlocale (LC_NUMERIC , old_locale.c_str ());
211- return val;
208+ const std::string old_locale = setlocale (LC_NUMERIC , nullptr );
209+ std::ignore = setlocale (LC_NUMERIC , " C" );
210+ const std::string str_copy (str.data (), str.size ());
211+ const double val = std::stod (str_copy);
212+ std::ignore = setlocale (LC_NUMERIC , old_locale.c_str ());
213+ return static_cast <float >(val);
212214}
213215
214216template <>
@@ -439,7 +441,7 @@ bool IsAllowedPortName(StringView str)
439441 return false ;
440442 }
441443 const char first_char = str.data ()[0 ];
442- if (! std::isalpha (first_char))
444+ if (std::isalpha (static_cast < unsigned char >( first_char)) == 0 )
443445 {
444446 return false ;
445447 }
@@ -467,7 +469,7 @@ bool IsReservedAttribute(StringView str)
467469
468470Any convertFromJSON (StringView json_text, std::type_index type)
469471{
470- nlohmann::json json = nlohmann::json::parse (json_text);
472+ const nlohmann::json json = nlohmann::json::parse (json_text);
471473 auto res = JsonExporter::get ().fromJson (json, type);
472474 if (!res)
473475 {
@@ -488,8 +490,18 @@ Expected<std::string> toJsonString(const Any& value)
488490
489491bool StartWith (StringView str, StringView prefix)
490492{
491- return str.size () >= prefix.size () &&
492- strncmp (str.data (), prefix.data (), prefix.size ()) == 0 ;
493+ if (str.size () < prefix.size ())
494+ {
495+ return false ;
496+ }
497+ for (size_t i = 0 ; i < prefix.size (); ++i)
498+ {
499+ if (str[i] != prefix[i])
500+ {
501+ return false ;
502+ }
503+ }
504+ return true ;
493505}
494506
495507bool StartWith (StringView str, char prefix)
0 commit comments