Skip to content

Commit

Permalink
yarpDeviceParamParserGenerator: fix to allow descriptions containing …
Browse files Browse the repository at this point in the history
…double quotes characters. Parser files regenerated
  • Loading branch information
randaz81 committed Feb 11, 2024
1 parent 0865472 commit 8d2d4a0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/devices/deviceBundler/DeviceBundler_ParamsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/yarpDeviceParamParserGenerator/parse_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
4 changes: 2 additions & 2 deletions src/yarpDeviceParamParserGenerator/parse_md.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 | - |
Expand All @@ -61,6 +61,7 @@
class TestDeviceWGP_ParamsParser : public yarp::dev::IDeviceDriverParams
{
public:
TestDeviceWGP_ParamsParser() = default;
~TestDeviceWGP_ParamsParser() override = default;

public:
Expand All @@ -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};
Expand Down
15 changes: 14 additions & 1 deletion src/yarpDeviceParamParserGenerator/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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

0 comments on commit 8d2d4a0

Please sign in to comment.