Created
June 20, 2012 20:15
-
-
Save ledbettj/2961947 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <ctype.h> | |
| /* convert a string in place from dash/underscore delimited format | |
| * to camel case. e.g. this-is-an_example => thisIsAnExample | |
| */ | |
| char* tocamel(char* str) | |
| { | |
| char* get = str; | |
| char* put = str; | |
| char c; | |
| int(*transform)(int) = tolower; | |
| while((c = *(get++)) != '\0') { | |
| switch(c){ | |
| case '-': | |
| case '_': | |
| transform = toupper; | |
| break; | |
| default: | |
| *(put++) = transform(c); | |
| transform = tolower; | |
| break; | |
| } | |
| } | |
| *put = '\0'; | |
| return str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment