Skip to content

Commit 27e99d7

Browse files
committed
Prevent the save tag to be weird
1 parent d414aaf commit 27e99d7

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

devices/YarpRobotLoggerDevice/src/YarpRobotLoggerDevice.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,38 @@ bool BipedalLocomotion::YarpRobotLoggerDevice::saveData(const std::string& tag)
26282628

26292629
if (!tag.empty())
26302630
{
2631-
inputFileName = defaultFilePrefix + "_" + tag;
2631+
std::string edited_tag = tag;
2632+
2633+
// Check if the tag is valid
2634+
for (size_t i = 1; i < edited_tag.size(); ++i)
2635+
{
2636+
if (!isalnum(edited_tag[i]) && (edited_tag[i] != '_') && (edited_tag[i] != ' '))
2637+
{
2638+
log()->error("{} The tag can contain only alphanumeric characters or "
2639+
"underscores (tag = \"{}\").",
2640+
logPrefix,
2641+
inputFileName);
2642+
return false;
2643+
}
2644+
}
2645+
2646+
// Check if the tag contains spaces. Trigger a warning if this is the case
2647+
// and replace the spaces with underscores
2648+
if (edited_tag.find(' ') != std::string::npos)
2649+
{
2650+
log()->warn("{} The tag \"{}\" contains spaces."
2651+
"They will be replaced with underscores.",
2652+
logPrefix,
2653+
edited_tag);
2654+
size_t start_pos = 0;
2655+
while ((start_pos = edited_tag.find(" ", start_pos)) != std::string::npos)
2656+
{
2657+
edited_tag.replace(start_pos, std::string(" ").length(), "_");
2658+
start_pos += std::string("_").length();
2659+
}
2660+
}
2661+
2662+
inputFileName = defaultFilePrefix + "_" + edited_tag;
26322663
}
26332664

26342665
{

0 commit comments

Comments
 (0)