| 20 | { |
| 21 | |
| 22 | bool CheckStringEquality(const std::string& v1, const std::string& v2, |
| 23 | const ScriptingEnumsRegistry* enums) |
| 24 | { |
| 25 | // compare strings first |
| 26 | if(v1 == v2) |
| 27 | { |
| 28 | return true; |
| 29 | } |
| 30 | // compare as integers next |
| 31 | auto ToInt = [enums](const std::string& str, auto& result) -> bool { |
| 32 | if(enums) |
| 33 | { |
| 34 | auto it = enums->find(str); |
| 35 | if(it != enums->end()) |
| 36 | { |
| 37 | result = it->second; |
| 38 | return true; |
| 39 | } |
| 40 | } |
| 41 | #if __cpp_lib_to_chars >= 201611L |
| 42 | auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result); |
| 43 | return (ec == std::errc()); |
| 44 | #else |
| 45 | try |
| 46 | { |
| 47 | result = std::stoi(str); |
| 48 | return true; |
| 49 | } |
| 50 | catch(...) |
| 51 | { |
| 52 | return false; |
| 53 | } |
| 54 | #endif |
| 55 | }; |
| 56 | int v1_int = 0; |
| 57 | int v2_int = 0; |
| 58 | if(ToInt(v1, v1_int) && ToInt(v2, v2_int) && v1_int == v2_int) |
| 59 | { |
| 60 | return true; |
| 61 | } |
| 62 | // compare as real numbers next |
| 63 | auto ToReal = [](const std::string& str, auto& result) -> bool { |
| 64 | #if __cpp_lib_to_chars >= 201611L |
| 65 | auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result); |
| 66 | return (ec == std::errc()); |
| 67 | #else |
| 68 | try |
| 69 | { |
| 70 | result = std::stod(str); |
| 71 | return true; |
| 72 | } |
| 73 | catch(...) |
| 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | #endif |
| 78 | }; |
| 79 | double v1_real = 0; |