Created
March 12, 2019 16:32
-
-
Save devhawk/c1d4765110baf764f4defbc8a03ae9ce to your computer and use it in GitHub Desktop.
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
void write_snake_case(writer& w, std::string_view const& name, bool uppercase) | |
{ | |
auto case_func = [uppercase](char c) | |
{ | |
return uppercase | |
? static_cast<char>(::toupper(c)) | |
: static_cast<char>(::tolower(c)); | |
}; | |
w.write(case_func(name[0])); | |
for (std::string_view::size_type i = 1; i < name.size() - 1; i++) | |
{ | |
if (name.substr(i, 4) == "UInt") | |
{ | |
w.write('_'); | |
} | |
if (isupper(name[i]) && islower(name[i + 1])) | |
{ | |
if (name.substr(i-1, 4) != "UInt") | |
{ | |
w.write('_'); | |
} | |
} | |
w.write(case_func(name[i])); | |
} | |
w.write(case_func(name[name.size() - 1])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment