Add string decode/encode api

This commit is contained in:
Thomas Krijnen
2026-08-22 13:12:36 +02:00
parent a5e94cf0d8
commit 87bc6bfbab
8 changed files with 55 additions and 5 deletions
+20
View File
@@ -550,6 +550,26 @@ std::string token::to_string() {
return result;
}
std::string ifcopenshell::encode_spf_string(const std::string& value) {
return character_encoder(value);
}
std::string ifcopenshell::decode_spf_string(const std::string& value) {
std::string wrapped;
auto value_p = &value;
if (!value.empty() && value.front() != '\'') {
wrapped = "'" + value + "'";
value_p = &wrapped;
}
file_reader<full_buffer_impl> reader(*value_p, caller_fed_tag{});
spf_lexer<file_reader<full_buffer_impl>> lexer(&reader);
token decoded = lexer.next();
if (!decoded.is_string()) {
throw exception("Expected an SPF string");
}
return decoded.as_string();
}
namespace {
template<typename Variant, typename T>