From 8d2d4a0f9194f0c54fefea725f0b070e7561dac4 Mon Sep 17 00:00:00 2001 From: Marco Randazzo Date: Sun, 11 Feb 2024 01:37:37 +0100 Subject: [PATCH] yarpDeviceParamParserGenerator: fix to allow descriptions containing double quotes characters. Parser files regenerated --- .../AudioToFileDevice_ParamsParser.h | 4 ++-- .../deviceBundler/DeviceBundler_ParamsParser.h | 4 ++-- src/yarpDeviceParamParserGenerator/parse_ini.cpp | 4 ++-- src/yarpDeviceParamParserGenerator/parse_md.cpp | 4 ++-- .../tests/TestDeviceWGP_ParamsParser.h | 7 ++++--- src/yarpDeviceParamParserGenerator/utils.h | 15 ++++++++++++++- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/devices/audioToFileDevice/AudioToFileDevice_ParamsParser.h b/src/devices/audioToFileDevice/AudioToFileDevice_ParamsParser.h index a034a1acd7..f0267ac65b 100644 --- a/src/devices/audioToFileDevice/AudioToFileDevice_ParamsParser.h +++ b/src/devices/audioToFileDevice/AudioToFileDevice_ParamsParser.h @@ -8,7 +8,7 @@ // This is an automatically generated file. Please do not edit it. // It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. -// Generated on: Fri Feb 9 16:59:13 2024 +// Generated on: Sun Feb 11 01:26:28 2024 #ifndef AUDIOTOFILEDEVICE_PARAMSPARSER_H @@ -54,7 +54,7 @@ class AudioToFileDevice_ParamsParser : public yarp::dev::IDeviceDriverParams int major = 1; int minor = 0; }; - const parser_version_type m_parser_version; + const parser_version_type m_parser_version = {}; std::string m_file_name = {"audio_out.wav"}; std::string m_save_mode = {"overwrite_file"}; bool m_add_marker = {false}; diff --git a/src/devices/deviceBundler/DeviceBundler_ParamsParser.h b/src/devices/deviceBundler/DeviceBundler_ParamsParser.h index 0893fa5d2a..b9201c6933 100644 --- a/src/devices/deviceBundler/DeviceBundler_ParamsParser.h +++ b/src/devices/deviceBundler/DeviceBundler_ParamsParser.h @@ -8,7 +8,7 @@ // This is an automatically generated file. Please do not edit it. // It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. -// Generated on: Fri Feb 9 16:59:13 2024 +// Generated on: Sun Feb 11 01:26:28 2024 #ifndef DEVICEBUNDLER_PARAMSPARSER_H @@ -54,7 +54,7 @@ class DeviceBundler_ParamsParser : public yarp::dev::IDeviceDriverParams int major = 1; int minor = 0; }; - const parser_version_type m_parser_version; + const parser_version_type m_parser_version = {}; std::string m_wrapper_device = {"device_name1"}; std::string m_attached_device = {"device_name2"}; bool m_doNotAttach = {false}; diff --git a/src/yarpDeviceParamParserGenerator/parse_ini.cpp b/src/yarpDeviceParamParserGenerator/parse_ini.cpp index 7bbf9d5e97..0261b5b1d7 100644 --- a/src/yarpDeviceParamParserGenerator/parse_ini.cpp +++ b/src/yarpDeviceParamParserGenerator/parse_ini.cpp @@ -74,11 +74,11 @@ bool ParamsFilesGenerator::parseIniParams(const std::string inputfilename) } else if (attribute == "description") { - param.description = trimSpaces(value); + param.description = trimSpaces(escapeQuotes(value)); } else if (attribute == "notes") { - param.notes = trimSpaces(value); + param.notes = trimSpaces(escapeQuotes(value)); } else if (attribute == "optionalVariableName") { diff --git a/src/yarpDeviceParamParserGenerator/parse_md.cpp b/src/yarpDeviceParamParserGenerator/parse_md.cpp index 24f97571f3..bf69bd8024 100644 --- a/src/yarpDeviceParamParserGenerator/parse_md.cpp +++ b/src/yarpDeviceParamParserGenerator/parse_md.cpp @@ -103,11 +103,11 @@ bool ParamsFilesGenerator::parseMdParams(const std::string inputfilename) param.required = true; std::getline(ss, item, '|'); - param.description = trimSpaces(item); + param.description = trimSpaces(escapeQuotes(item)); if (containsOnlySymbols(param.description)) param.description = ""; std::getline(ss, item, '|'); - param.notes = trimSpaces(item); + param.notes = trimSpaces(escapeQuotes(item)); if (containsOnlySymbols(param.notes)) param.notes = ""; std::getline(ss, item, '\n'); diff --git a/src/yarpDeviceParamParserGenerator/tests/TestDeviceWGP_ParamsParser.h b/src/yarpDeviceParamParserGenerator/tests/TestDeviceWGP_ParamsParser.h index 534ef601c5..dae5aed231 100644 --- a/src/yarpDeviceParamParserGenerator/tests/TestDeviceWGP_ParamsParser.h +++ b/src/yarpDeviceParamParserGenerator/tests/TestDeviceWGP_ParamsParser.h @@ -8,7 +8,7 @@ // This is an automatically generated file. Please do not edit it. // It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. -// Generated on: Wed Feb 7 16:19:38 2024 +// Generated on: Sun Feb 11 01:28:40 2024 #ifndef TESTDEVICEWGP_PARAMSPARSER_H @@ -42,7 +42,7 @@ * | group2 | param_a | bool | - | false | 0 | Some description of param. | - | * | - | period | double | s | - | 1 | Algorithm control loop period | - | * | - | initial_ref | double | m | 3 | 0 | An initial value for the algorithm | - | -* | group3::subgroup1 | param_1 | bool | - | false | 1 | This is a parameter for testing purposes | - | +* | group3::subgroup1 | param_1 | bool | - | false | 1 | This is a parameter for \"testing\" purposes | - | * | group3::subgroup1 | param_2 | bool | - | true | 0 | This is a parameter for testing purposes | - | * | group3 | param_3 | bool | - | false | 0 | This is a parameter for testing purposes | - | * | group3::subgroup2 | param_4 | bool | - | true | 0 | This is a parameter for testing purposes | - | @@ -61,6 +61,7 @@ class TestDeviceWGP_ParamsParser : public yarp::dev::IDeviceDriverParams { public: + TestDeviceWGP_ParamsParser() = default; ~TestDeviceWGP_ParamsParser() override = default; public: @@ -71,7 +72,7 @@ class TestDeviceWGP_ParamsParser : public yarp::dev::IDeviceDriverParams int major = 1; int minor = 0; }; - const parser_version_type m_parser_version; + const parser_version_type m_parser_version = {}; std::string m_file_name = {"audio_out.wav"}; std::string m_mode = {"mode1"}; bool m_add_marker = {false}; diff --git a/src/yarpDeviceParamParserGenerator/utils.h b/src/yarpDeviceParamParserGenerator/utils.h index 94e84ca31f..c1dad068ce 100644 --- a/src/yarpDeviceParamParserGenerator/utils.h +++ b/src/yarpDeviceParamParserGenerator/utils.h @@ -39,7 +39,7 @@ inline bool containsOnlySymbols(const std::string& str) { return true; // If all characters are symbols, return true } -//remove all spaces from a string +//remove all traling/leading spaces from a string inline std::string trimSpaces(const std::string& str) { size_t firstNonSpace = str.find_first_not_of(" \t"); size_t lastNonSpace = str.find_last_not_of(" \t"); @@ -52,4 +52,17 @@ inline std::string trimSpaces(const std::string& str) { } } +//add the escape character in front of each special character of a string +inline std::string escapeQuotes(const std::string& str) +{ + std::string result; + for (char c : str) { + if (c == '"') { + result.push_back('\\'); + } + result.push_back(c); + } + return result; +} + #endif