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
@@ -95,6 +95,8 @@ from .sql import sqlite, sqlite_entity
rocksdb_lazy_instance = file_module.rocksdb_lazy_instance
decode_spf_string = ifcopenshell_wrapper.decode_spf_string
encode_spf_string = ifcopenshell_wrapper.encode_spf_string
get_log = ifcopenshell_wrapper.get_log
logger = ifcopenshell_wrapper.logger if hasattr(ifcopenshell_wrapper, "logger") else None
if hasattr(ifcopenshell_wrapper, "logger_or_root"):
@@ -114,6 +116,8 @@ def optional_logger_args(logger: ifcopenshell_wrapper.logger | None) -> tuple[lo
# (it's a requirement for a typed library)
__all__ = [
"clear_plugin_search_paths",
"decode_spf_string",
"encode_spf_string",
"entity_instance",
"file",
"get_plugin_search_paths",
@@ -1649,6 +1649,8 @@ def construct_iterator_with_include_exclude_id(
geometry_library, settings, file, elems, include, num_threads, logger=None
): ...
def convert_loop_to_function_item(loop): ...
def decode_spf_string(value: str) -> str: ...
def encode_spf_string(value: str) -> str: ...
class attribute_value_derived: ...
@@ -1,6 +1,14 @@
import ifcopenshell
def test_spf_strings_can_be_encoded_and_decoded():
decoded = "Café's \\"
encoded = r"'Caf\X2\00E9\X0\''s \\'"
assert ifcopenshell.encode_spf_string(decoded) == encoded
assert ifcopenshell.decode_spf_string(encoded) == decoded
def test_skip_over_non_entity_instance():
data = """
ISO-10303-21;