Skip to content

Commit

Permalink
Merge branch 'main' into fix/python-xmlization
Browse files Browse the repository at this point in the history
  • Loading branch information
mristin authored Feb 14, 2024
2 parents 805024b + 14ef14f commit 487ebaf
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 42 deletions.
4 changes: 4 additions & 0 deletions aas_core_codegen/cpp/aas_common/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h> on Windows
Expand Down
4 changes: 2 additions & 2 deletions aas_core_codegen/cpp/stringification/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _generate_model_type_from_string_implementation(
{I}if (it == {map_name}.end()) {{
{II}throw std::invalid_argument(
{III}common::Concat(
{IIII}"Unexpected model type literal: ",
{IIII}"Unexpected {enum_name} literal: ",
{IIII}text
{III})
{II});
Expand Down Expand Up @@ -364,7 +364,7 @@ def _generate_enum_from_string_implementation(
{I}if (it == {map_name}.end()) {{
{II}throw std::invalid_argument(
{III}common::Concat(
{IIII}"Unexpected model type literal: ",
{IIII}"Unexpected {enum_name} literal: ",
{IIII}text
{III})
{II});
Expand Down
8 changes: 4 additions & 4 deletions aas_core_codegen/cpp/wstringification/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _generate_model_type_from_wstring_implementation(
{II}throw std::invalid_argument(
{III}common::WstringToUtf8(
{IIII}common::Concat(
{IIIII}L"Unexpected model type literal: ",
{IIIII}L"Unexpected {enum_name} literal: ",
{IIIII}text
{IIII})
{III})
Expand Down Expand Up @@ -214,7 +214,7 @@ def _generate_model_type_to_wstring_implementation(
default:
{I}throw std::invalid_argument(
{II}common::Concat(
{III}"Unexpected model type: ",
{III}"Unexpected {enum_name} literal: ",
{III}std::to_string(
{IIII}static_cast<std::uint32_t>({model_type_arg})
{III})
Expand Down Expand Up @@ -365,7 +365,7 @@ def _generate_enum_from_wstring_implementation(
{II}throw std::invalid_argument(
{III}common::WstringToUtf8(
{IIII}common::Concat(
{IIIII}L"Unexpected model type literal: ",
{IIIII}L"Unexpected {enum_name} literal: ",
{IIIII}text
{IIII})
{III})
Expand Down Expand Up @@ -432,7 +432,7 @@ def _generate_enum_to_wstring_implementation(
default:
{I}throw std::invalid_argument(
{II}common::Concat(
{III}"Unexpected literal: ",
{III}"Unexpected {enum_name} literal: ",
{III}std::to_string(
{IIII}static_cast<std::uint32_t>({literal_arg})
{III})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>
<head>
<title>Replace curly brackets, backslashes and indent</title>
<script>
function processInput() {
var input = document.getElementById("input");
var output = document.getElementById("output");

var text = input.value
.replaceAll("{", "{{")
.replaceAll("}", "}}")
.replaceAll(/^ /gm, "{IIIII}")
.replaceAll(/^ /gm, "{IIII}")
.replaceAll(/^ /gm, "{III}")
.replaceAll(/^ /gm, "{II}")
.replaceAll(/^ /gm, "{I}")
.replaceAll("\\", "\\\\");

output.value = text;
}

function copyOutput() {
var output = document.getElementById("output");
output.select();
document.execCommand("copy");
}

window.onload = function() {
processInput();
}
</script>
</head>
<body>
<textarea id="input" cols="120" rows="10" oninput="processInput()"></textarea>
<br/><br/><br/>
<textarea id="output" cols="120" rows="10" readonly></textarea>
<br/><br/><br/>
<button onclick="copyOutput()">Copy</button>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h> on Windows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ types::ModelType MustModelTypeFromString(
if (it == kModelTypeFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected ModelType literal: ",
text
)
);
Expand Down Expand Up @@ -327,7 +327,7 @@ types::ModellingKind MustModellingKindFromString(
if (it == kModellingKindFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected ModellingKind literal: ",
text
)
);
Expand Down Expand Up @@ -396,7 +396,7 @@ types::QualifierKind MustQualifierKindFromString(
if (it == kQualifierKindFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected QualifierKind literal: ",
text
)
);
Expand Down Expand Up @@ -467,7 +467,7 @@ types::AssetKind MustAssetKindFromString(
if (it == kAssetKindFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected AssetKind literal: ",
text
)
);
Expand Down Expand Up @@ -594,7 +594,7 @@ types::AasSubmodelElements MustAasSubmodelElementsFromString(
if (it == kAasSubmodelElementsFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected AasSubmodelElements literal: ",
text
)
);
Expand Down Expand Up @@ -689,7 +689,7 @@ types::EntityType MustEntityTypeFromString(
if (it == kEntityTypeFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected EntityType literal: ",
text
)
);
Expand Down Expand Up @@ -754,7 +754,7 @@ types::Direction MustDirectionFromString(
if (it == kDirectionFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected Direction literal: ",
text
)
);
Expand Down Expand Up @@ -819,7 +819,7 @@ types::StateOfEvent MustStateOfEventFromString(
if (it == kStateOfEventFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected StateOfEvent literal: ",
text
)
);
Expand Down Expand Up @@ -884,7 +884,7 @@ types::ReferenceTypes MustReferenceTypesFromString(
if (it == kReferenceTypesFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected ReferenceTypes literal: ",
text
)
);
Expand Down Expand Up @@ -1037,7 +1037,7 @@ types::KeyTypes MustKeyTypesFromString(
if (it == kKeyTypesFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected KeyTypes literal: ",
text
)
);
Expand Down Expand Up @@ -1258,7 +1258,7 @@ types::DataTypeDefXsd MustDataTypeDefXsdFromString(
if (it == kDataTypeDefXsdFromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected DataTypeDefXsd literal: ",
text
)
);
Expand Down Expand Up @@ -1447,7 +1447,7 @@ types::DataTypeIec61360 MustDataTypeIec61360FromString(
if (it == kDataTypeIec61360FromStringMap.end()) {
throw std::invalid_argument(
common::Concat(
"Unexpected model type literal: ",
"Unexpected DataTypeIec61360 literal: ",
text
)
);
Expand Down
Loading

0 comments on commit 487ebaf

Please sign in to comment.