Skip to content
Snippets Groups Projects
Commit 2943965b authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

add camel2snake conversion

parent 9e1e89e0
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,45 @@
namespace armarx::aron::codegenerator::cpp
{
// Function to convert camel case
// string to snake case string
std::string camelToSnake(const std::string& str)
{
// Empty String
std::string result = "";
// Append first character(in lower case)
// to result string
char c = std::tolower(str[0]);
result+=(char(c));
// Traverse the string from
// ist index to last index
for (unsigned int i = 1; i < str.length(); i++) {
char ch = str[i];
// Check if the character is upper case
// then append '_' and such character
// (in lower case) to result string
if (std::isupper(ch)) {
result = result + '_';
result+=char(std::tolower(ch));
}
// If the character is lower case then
// add such character into result string
else {
result = result + ch;
}
}
// return the result
return result;
}
Writer::Writer(const std::string& producerName, const std::vector<std::string>& additionalIncludesFromXMLFile) :
CodeWriter(producerName, additionalIncludesFromXMLFile)
{
......@@ -361,7 +400,7 @@ namespace armarx::aron::codegenerator::cpp
std::vector<std::string> namespaces = info.getNamespaces();
std::string rawObjectName = info.getNameWithoutNamespace();
namespaces.push_back(simox::alg::to_lower(rawObjectName) + "_details");
namespaces.push_back(simox::alg::to_lower(camelToSnake(rawObjectName)) + "_details");
std::string enumdoc = "The enum definition of the enum of the auogenerated class '" + gen.getFullClassCppTypename() + "'.";
CppEnumPtr e = std::make_shared<CppEnum>(namespaces, "Enum");
......@@ -476,7 +515,7 @@ namespace armarx::aron::codegenerator::cpp
void Writer::setupMemberFields(CppClassPtr& c, const std::map<std::string, std::string>& doc_members, const generator::IntEnumClass& o) const
{
auto publicFields = o.getPublicVariableDeclarations(c->getName());
auto publicFields = o.getPublicVariableDeclarations(camelToSnake(c->getName()));
for (const auto& f : publicFields)
{
if (auto it = doc_members.find(f->getName()); it != doc_members.end())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment