sanitize_typename.cpp
Go to the documentation of this file.
1#include "sanitize_typename.h"
2
3#include <sstream>
4
5#include <SimoxUtility/algorithm/string.h>
6
7#include <RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>
8
9
11 armarx::armem::arondto::MemoryID::ToAronType()->getFullName();
13
14namespace
15{
16 std::string
17 remove_wrap(const std::string& string, const std::string& prefix, const std::string& suffix)
18 {
19 if (simox::alg::starts_with(string, prefix) && simox::alg::ends_with(string, suffix))
20 {
21 return string.substr(prefix.size(), string.size() - prefix.size() - suffix.size());
22 }
23 else
24 {
25 return string;
26 }
27 }
28} // namespace
29
30std::string
32{
33 if (typeName == rawMemoryIDTypeName)
34 {
36 }
37
38 namespace s = simox::alg;
39 std::string n = typeName;
40 n = s::replace_all(n, "armarx::aron::type::", "");
41 n = s::replace_all(n, "armarx::aron::data::", "");
42
43 if (s::starts_with(n, "Object<"))
44 {
45 n = remove_wrap(n, "Object<", ">");
46 const std::string del = "::"; // remove namespace
47 size_t find = n.rfind(del);
48 if (find != n.npos)
49 {
50 find += del.size(); // include del
51 std::stringstream ss;
52 ss << n.substr(find) << " (" << n.substr(0, find - del.size()) << ")";
53 n = ss.str();
54 }
55 }
56 else
57 {
58 if (s::contains(n, "<")) // another containertype
59 {
60 std::string container = n.substr(0, n.find("<"));
61 std::string subtype = remove_wrap(n, (container + "<"), ">");
62 subtype = sanitizeTypeName(subtype);
63 n = n.substr(0, n.find("<") + 1) + subtype + ">";
64 }
65 }
66
67 return n;
68}
std::string sanitizeTypeName(const std::string &typeName)
const std::string sanitizedMemoryIDTypeName