33 return value ?
"true" :
"false";
37 std::string toStr<std::string>(
const std::string& value)
115 return std::string(str.data(), str.size());
122 auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
123 if(ec != std::errc())
133 unsigned long result = 0;
134 auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
135 if(ec != std::errc())
142 template <
typename T>
146 if(res < std::numeric_limits<T>::lowest() || res > std::numeric_limits<T>::max())
149 StrCat(
"Value out of bound when converting [", str,
"] to integer"));
157 return ConvertWithBoundCheck<int8_t>(str);
163 return ConvertWithBoundCheck<int16_t>(str);
169 return ConvertWithBoundCheck<int32_t>(str);
175 return ConvertWithBoundCheck<uint8_t>(str);
181 return ConvertWithBoundCheck<uint16_t>(str);
187 return ConvertWithBoundCheck<uint32_t>(str);
196 std::string old_locale = setlocale(LC_NUMERIC,
nullptr);
197 setlocale(LC_NUMERIC,
"C");
198 double val = std::stod(str.data());
199 setlocale(LC_NUMERIC, old_locale.c_str());
206 std::string old_locale = setlocale(LC_NUMERIC,
nullptr);
207 setlocale(LC_NUMERIC,
"C");
208 float val = std::stof(str.data());
209 setlocale(LC_NUMERIC, old_locale.c_str());
214 std::vector<int> convertFromString<std::vector<int>>(
StringView str)
217 std::vector<int> output;
218 output.reserve(parts.size());
221 output.push_back(convertFromString<int>(part));
227 std::vector<double> convertFromString<std::vector<double>>(
StringView str)
230 std::vector<double> output;
231 output.reserve(parts.size());
240 std::vector<std::string> convertFromString<std::vector<std::string>>(
StringView str)
243 std::vector<std::string> output;
244 output.reserve(parts.size());
247 output.push_back(convertFromString<std::string>(part));
266 else if(str.size() == 4)
268 if(str ==
"true" || str ==
"TRUE" || str ==
"True")
273 else if(str.size() == 5)
275 if(str ==
"false" || str ==
"FALSE" || str ==
"False")
280 throw RuntimeError(
"convertFromString(): invalid bool conversion");
297 throw RuntimeError(std::string(
"Cannot convert this to NodeStatus: ") +
298 static_cast<std::string
>(str));
306 if(str ==
"Condition")
310 if(str ==
"Decorator")
320 if(str ==
"Input" || str ==
"INPUT")
322 if(str ==
"Output" || str ==
"OUTPUT")
324 if(str ==
"InOut" || str ==
"INOUT")
326 throw RuntimeError(std::string(
"Cannot convert this to PortDirection: ") +
327 static_cast<std::string
>(str));
350 std::vector<StringView> splitted_strings;
351 splitted_strings.reserve(4);
354 while(pos < strToSplit.size())
356 size_t new_pos = strToSplit.find_first_of(delimeter, pos);
357 if(new_pos == std::string::npos)
359 new_pos = strToSplit.size();
361 const auto sv =
StringView{ &strToSplit.data()[pos], new_pos - pos };
362 splitted_strings.push_back(sv);
365 return splitted_strings;
423 if(str ==
"_autoremap")
431 const char first_char = str.data()[0];
432 if(!std::isalpha(first_char))
436 if(str ==
"name" || str ==
"ID")
449 throw std::runtime_error(res.error());
461 return nonstd::make_unexpected(
"toJsonString failed");
466 return str.size() >= prefix.size() &&
467 strncmp(str.data(), prefix.data(), prefix.size()) == 0;
472 return str.size() >= 1 && str[0] == prefix;