Created
October 25, 2020 19:08
-
-
Save pallas/8b8572fc0daa75ea312eafcf9dc3149e to your computer and use it in GitHub Desktop.
in-place conversion of string from snake case to camel case
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
// SPDX-License-Identifier: Unlicense | |
// Author: Derrick Lyndon Pallas <[email protected]> | |
#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