calculate length of strings with length function

This commit is contained in:
pantor
2019-04-07 13:27:43 +02:00
parent 3afc7f30cd
commit 6698e98ea3
3 changed files with 28 additions and 10 deletions
+12 -4
View File
@@ -180,11 +180,11 @@ class Renderer {
}
case Bytecode::Op::PrintValue: {
const json& val = *get_args(bc)[0];
if (val.is_string())
if (val.is_string()) {
os << val.get_ref<const std::string&>();
else
} else {
os << val.dump();
// val.dump(os);
}
pop_args(bc);
break;
}
@@ -215,7 +215,15 @@ class Renderer {
break;
}
case Bytecode::Op::Length: {
auto result = get_args(bc)[0]->size();
const json& val = *get_args(bc)[0];
int result;
if (val.is_string()) {
result = val.get_ref<const std::string&>().length();
} else {
result = val.size();
}
pop_args(bc);
m_stack.emplace_back(result);
break;