Skip to content

Instantly share code, notes, and snippets.

@ledbettj
Created June 20, 2012 20:15
Show Gist options
  • Select an option

  • Save ledbettj/2961947 to your computer and use it in GitHub Desktop.

Select an option

Save ledbettj/2961947 to your computer and use it in GitHub Desktop.
#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