Skip to content

Commit 6b98d8d

Browse files
committed
[#24061] Updated read_next_command() for the new FastDDS-Spy filter
Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent fd0f9f5 commit 6b98d8d

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

cpp_utils/include/cpp_utils/user_interface/CommandReader.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class CommandReader
9494
void read_command_callback_(
9595
std::string command_read);
9696

97+
std::vector<std::string> join_quoted_strings(
98+
const std::vector<std::string>& input);
99+
97100
//! Builder to transform string into a command enum value.
98101
EnumBuilder<CommandEnum> builder_;
99102

cpp_utils/include/cpp_utils/user_interface/impl/CommandReader.ipp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,45 @@ bool CommandReader<CommandEnum>::read_next_command(
4545
std::string full_command = commands_read_.consume();
4646

4747
// Divide command
48-
command.arguments = utils::split_string(full_command, " ");
49-
48+
command.arguments = join_quoted_strings(utils::split_string(full_command, " "));
5049
// Check if command exists
5150
// The args are already set in command, and the enum value will be set string_to_enumeration
5251
return builder_.string_to_enumeration(command.arguments[0], command.command);
5352
}
5453

54+
template <typename CommandEnum>
55+
std::vector<std::string> CommandReader<CommandEnum>::join_quoted_strings(
56+
const std::vector<std::string>& input)
57+
{
58+
std::vector<std::string> result;
59+
60+
for (size_t i = 0; i < input.size(); ++i)
61+
{
62+
// Check if string starts with a quote
63+
if (!input[i].empty() && input[i].front() == '"')
64+
{
65+
std::string joined = input[i];
66+
67+
// Keep joining until we find a string ending with a quote
68+
while (i + 1 < input.size() &&
69+
(joined.empty() || joined.back() != '"'))
70+
{
71+
joined += " " + input[++i];
72+
}
73+
74+
result.push_back(joined.substr(1, joined.size() - 2));
75+
}
76+
else
77+
{
78+
result.push_back(input[i]);
79+
}
80+
}
81+
82+
return result;
83+
}
84+
85+
86+
5587
template <typename CommandEnum>
5688
void CommandReader<CommandEnum>::read_command_callback_(
5789
std::string command_read)

0 commit comments

Comments
 (0)