Jump to content

Camel case and snake case: Difference between revisions

m
Small improvement to coding.
m (Small improvement to code.)
m (Small improvement to coding.)
Line 468:
The output of this example reflects the author's interpretation of the task.
<syntaxhighlight lang="c++">
 
#include <algorithm>
#include <iomanip>
Line 491 ⟶ 492:
std::string trim(const std::string& text) {
return left_trim(right_trim(text));
}
 
void prepare_for_conversion(std::string& text) {
text = trim(text);
std::replace(cameltext.begin(), cameltext.end(), SPACE, UNDERSCORE);
std::replace(cameltext.begin(), cameltext.end(), HYPHEN, UNDERSCORE);
}
 
std::string to_snake_case(std::string& camel) {
camel = trimprepare_for_conversion(camel);
std::replace(camel.begin(), camel.end(), SPACE, UNDERSCORE);
std::replace(camel.begin(), camel.end(), HYPHEN, UNDERSCORE);
std::string snake = "";
bool first = true;
Line 518 ⟶ 523:
 
std::string to_camel_case(std::string& snake) {
snake = trimprepare_for_conversion(snake);
std::replace(snake.begin(), snake.end(), SPACE, UNDERSCORE);
std::replace(snake.begin(), snake.end(), HYPHEN, UNDERSCORE);
std::string camel = "";
bool underscore = false;
897

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.