-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More robust handling of the type names
- Loading branch information
1 parent
7419533
commit 3031862
Showing
7 changed files
with
102 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef RFL_INTERNAL_STRINGS_TOPASCALCASE_HPP_ | ||
#define RFL_INTERNAL_STRINGS_TOPASCALCASE_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace rfl { | ||
namespace internal { | ||
namespace strings { | ||
|
||
inline char to_upper(const char ch) { | ||
if (ch >= 'a' && ch <= 'z') { | ||
return ch + ('A' - 'a'); | ||
} else { | ||
return ch; | ||
} | ||
} | ||
|
||
/// Splits a string alongside the delimiter | ||
inline std::string to_pascal_case(const std::string& _str) { | ||
std::string result; | ||
bool capitalize = true; | ||
for (const char ch : _str) { | ||
if (ch == '_') { | ||
capitalize = true; | ||
} else if (capitalize) { | ||
result.push_back(to_upper(ch)); | ||
capitalize = false; | ||
} else { | ||
result.push_back(ch); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
} // namespace strings | ||
} // namespace internal | ||
} // namespace rfl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef RFL_PARSING_MAKETYPENAME_HPP_ | ||
#define RFL_PARSING_MAKETYPENAME_HPP_ | ||
|
||
#include "../type_name_t.hpp" | ||
#include "is_tagged_union_wrapper.hpp" | ||
|
||
namespace rfl { | ||
namespace parsing { | ||
|
||
inline std::string replace_non_alphanumeric(std::string _str) { | ||
for (auto& ch : _str) { | ||
ch = std::isalnum(ch) ? ch : '_'; | ||
} | ||
return _str; | ||
} | ||
|
||
template <class U> | ||
static std::string make_type_name() { | ||
if constexpr (is_tagged_union_wrapper_v<U>) { | ||
return replace_non_alphanumeric(type_name_t<typename U::Type>().str() + | ||
"__tagged"); | ||
} else { | ||
return replace_non_alphanumeric(type_name_t<U>().str()); | ||
} | ||
} | ||
|
||
} // namespace parsing | ||
} // namespace rfl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters