Use std::string for string-formatted values (#1360)

* Use `std::string` for string-formatted values

* Make `formatString` and `formatNumber` be `const`
This commit is contained in:
Sylvie
2024-03-19 02:43:18 -04:00
committed by GitHub
parent 33dd97b6a0
commit fec2266dd8
5 changed files with 90 additions and 96 deletions

View File

@@ -1191,10 +1191,12 @@ static char const *readInterpolation(size_t depth) {
if (!sym) {
error("Interpolated symbol \"%s\" does not exist\n", fmtBuf.c_str());
} else if (sym->type == SYM_EQUS) {
fmt.printString(buf, sizeof(buf), sym->getEqus()->c_str());
std::string str = fmt.formatString(*sym->getEqus());
memcpy(buf, str.c_str(), str.length() + 1);
return buf;
} else if (sym->isNumeric()) {
fmt.printNumber(buf, sizeof(buf), sym->getConstantValue());
std::string str = fmt.formatNumber(sym->getConstantValue());
memcpy(buf, str.c_str(), str.length() + 1);
return buf;
} else {
error("Only numerical and string symbols can be interpolated\n");