Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
in-place conversion of string from snake case to camel case
// SPDX-License-Identifier: Unlicense
// Author: Derrick Lyndon Pallas <derrick@pallas.us>
#include <stdbool.h>
#include <ctype.h>
char *
snake_to_camel(char * string) {
bool upper = true;
char * camel = string;
for (const char * snake = string ; *snake ; ++snake) {
if (isalpha(*snake)) {
*camel++ = upper ? toupper(*snake) : tolower(*snake);
} else if (isdigit(*snake)) {
*camel++ = *snake;
}
upper = !isalpha(*snake);
}
*camel = '\0';
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment