Skip to content

Commit b243054

Browse files
committed
added remove string prefix
1 parent d82df2a commit b243054

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2024 Intelligent Robotics Lab - Gentlebots
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef CONFIGURATION__REMOVE_STRING_PREFIX_HPP_
16+
#define CONFIGURATION__REMOVE_STRING_PREFIX_HPP_
17+
18+
#include "behaviortree_cpp_v3/behavior_tree.h"
19+
#include "behaviortree_cpp_v3/bt_factory.h"
20+
21+
namespace configuration
22+
{
23+
24+
class RemoveStringPrefix : public BT::ActionNodeBase
25+
{
26+
public:
27+
explicit RemoveStringPrefix(const std::string & xml_tag_name, const BT::NodeConfiguration & conf);
28+
29+
void halt();
30+
BT::NodeStatus tick();
31+
32+
static BT::PortsList providedPorts()
33+
{
34+
return BT::PortsList(
35+
{
36+
BT::InputPort<std::string>("string_to_remove"),
37+
BT::InputPort<std::string>("prefix"),
38+
BT::OutputPort<std::string>("result")
39+
});
40+
}
41+
42+
private:
43+
std::string string_to_remove_;
44+
std::string prefix_;
45+
std::string result_;
46+
};
47+
48+
} // namespace configuration
49+
50+
#endif // CONFIGURATION__REMOVE_STRING_PREFIX_HPP_
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024 Intelligent Robotics Lab - Gentlebots
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "configuration/remove_string_prefix.hpp"
16+
17+
namespace configuration
18+
{
19+
20+
RemoveStringPrefix::RemoveStringPrefix(
21+
const std::string & xml_tag_name, const BT::NodeConfiguration & conf)
22+
: BT::ActionNodeBase(xml_tag_name, conf)
23+
{
24+
}
25+
26+
BT::NodeStatus RemoveStringPrefix::tick()
27+
{
28+
getInput("string_to_remove", string_to_remove_);
29+
getInput("prefix", prefix_);
30+
if (string_to_remove_.empty() || prefix_.empty()) {
31+
return BT::NodeStatus::FAILURE;
32+
}
33+
34+
size_t pos = string_to_remove_.find(prefix_);
35+
if (pos != std::string::npos) {
36+
result_ = string_to_remove_.substr(pos + prefix_.length());
37+
} else {
38+
result_ = string_to_remove_;
39+
}
40+
41+
setOutput("result", result_);
42+
return BT::NodeStatus::SUCCESS;
43+
}
44+
45+
void RemoveStringPrefix::halt() {}
46+
47+
} // namespace configuration
48+
49+
BT_REGISTER_NODES(factory)
50+
{
51+
factory.registerNodeType<configuration::RemoveStringPrefix>("RemoveStringPrefix");
52+
}

0 commit comments

Comments
 (0)