diff options
Diffstat (limited to 'src/bin/eolian_js/eolian/js/format.hh')
-rw-r--r-- | src/bin/eolian_js/eolian/js/format.hh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bin/eolian_js/eolian/js/format.hh b/src/bin/eolian_js/eolian/js/format.hh new file mode 100644 index 0000000000..a07d541e14 --- /dev/null +++ b/src/bin/eolian_js/eolian/js/format.hh @@ -0,0 +1,44 @@ +#ifndef EOLIAN_JS_FORMAT_HH +#define EOLIAN_JS_FORMAT_HH + +#include <eolian/js/domain.hh> + +#include <algorithm> +#include <string> +#include <cctype> + +namespace eolian { namespace js { + +namespace format { + +std::string generic(std::string const& in) +{ + std::string s = in; + auto i = s.find('_'); + while (i != std::string::npos) + { + if (i <= 0 || i+1 >= s.size() || + !::isalnum(s[i-1]) || !::isalnum(s[i+1])) + { + EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "Entity '" << in + << "' can't be conveniently converted to a JavaScript name."; + return in; + } + s[i+1] = static_cast<char>(::toupper(s[i+1])); + s.erase(i, 1); + i = s.find('_', i); + } + return s; +} + +std::string constant(std::string in) +{ + std::transform(in.begin(), in.end(), in.begin(), ::toupper); + return in; +} + +} + +} } + +#endif |