| 112 | } |
| 113 | |
| 114 | void Quantity::setDisplayValueString(std::string s) { |
| 115 | teVarsInit(); |
| 116 | |
| 117 | // Uppercase letters aren't needed in formulas, so convert to lowercase in case user types INF or C4. |
| 118 | s = string::lowercase(s); |
| 119 | |
| 120 | // Replace "#" with "s" so note names can be written as c#. |
| 121 | std::replace(s.begin(), s.end(), '#', 's'); |
| 122 | |
| 123 | // Compile string with tinyexpr |
| 124 | te_expr* expr = te_compile(s.c_str(), teVars.data(), teVars.size(), NULL); |
| 125 | if (!expr) |
| 126 | return; |
| 127 | |
| 128 | double result = te_eval(expr); |
| 129 | te_free(expr); |
| 130 | if (std::isnan(result)) |
| 131 | return; |
| 132 | |
| 133 | setDisplayValue(result); |
| 134 | } |
| 135 | |
| 136 | std::string Quantity::getString() { |
| 137 | std::string s; |
nothing calls this directly
no test coverage detected