From b195a9855ddaf5a6dfb16a65a9c8c2b42a9c124b Mon Sep 17 00:00:00 2001 From: Marko Ristin Date: Sat, 10 Feb 2024 17:45:50 +0100 Subject: [PATCH] Fix C++ to pass jsonization of concrete classes We fix the C++ generator so that the generator code passes all the tests related to jsonization of concrete classes. --- aas_core_codegen/cpp/aas_common/_generate.py | 4 ++ ...kets-backslashes-and-two-space-indent.html | 39 +++++++++++++++++++ .../expected_output/common.cpp | 4 ++ 3 files changed, 47 insertions(+) create mode 100644 dev_scripts/replace-curly-brackets-backslashes-and-two-space-indent.html diff --git a/aas_core_codegen/cpp/aas_common/_generate.py b/aas_core_codegen/cpp/aas_common/_generate.py index 414846933..0a79d023d 100644 --- a/aas_core_codegen/cpp/aas_common/_generate.py +++ b/aas_core_codegen/cpp/aas_common/_generate.py @@ -610,6 +610,10 @@ def generate_implementation(library_namespace: Stripped) -> str: {I}const char* utf8_text, {I}size_t utf8_text_size ) {{ +{I}if (utf8_text_size == 0) {{ +{II}return std::wstring(); +{I}}} + {I}#ifdef _WIN32 {I}// NOTE (mristin): {I}// We have to use MultiByteToWideChar from on Windows diff --git a/dev_scripts/replace-curly-brackets-backslashes-and-two-space-indent.html b/dev_scripts/replace-curly-brackets-backslashes-and-two-space-indent.html new file mode 100644 index 000000000..6f6e514ee --- /dev/null +++ b/dev_scripts/replace-curly-brackets-backslashes-and-two-space-indent.html @@ -0,0 +1,39 @@ + + +Replace curly brackets, backslashes and indent + + + + +


+ +


+ + diff --git a/test_data/cpp/test_main/aas_core_meta.v3/expected_output/common.cpp b/test_data/cpp/test_main/aas_core_meta.v3/expected_output/common.cpp index 3a5542860..7689d23b2 100644 --- a/test_data/cpp/test_main/aas_core_meta.v3/expected_output/common.cpp +++ b/test_data/cpp/test_main/aas_core_meta.v3/expected_output/common.cpp @@ -13976,6 +13976,10 @@ std::wstring Utf8ToWstring( const char* utf8_text, size_t utf8_text_size ) { + if (utf8_text_size == 0) { + return std::wstring(); + } + #ifdef _WIN32 // NOTE (mristin): // We have to use MultiByteToWideChar from on Windows