MCPcopy Create free account
hub / github.com/Tencent/libpag / SafeStringToFloat

Function SafeStringToFloat

exporter/src/utils/ConfigUtils.cpp:27–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace exporter {
26
27float SafeStringToFloat(std::string_view str, float defaultValue) {
28 if (str.empty()) {
29 return defaultValue;
30 }
31 try {
32 return std::stof(std::string(str));
33 } catch (const std::invalid_argument&) {
34 return defaultValue;
35 } catch (const std::out_of_range&) {
36 return defaultValue;
37 }
38}
39
40bool SafeStringEqual(const char* str, const char* target) {
41 if (!str || !target) {

Callers 1

ReadCommonConfigFunction · 0.85

Calls 1

emptyMethod · 0.80

Tested by

no test coverage detected