Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *sanitize_name(char *outbuf, const char *input, int length) {
- char hex[3] ;
- char temp[strlen(input)*2+1] ;
- char *output = temp ;
- if(!isalpha(*input) && *input != '_')
- *(output++) = '_';
- while(*input) {
- if(isalnum(*input))
- *(output++) = *input ;
- else if(*input == ' ' || *input == '-') {
- *(output++) = '_' ;}
- else {
- sprintf(hex, "%.2x", *input) ;
- strcpy(output, hex) ;
- output += 2 ;}
- input++ ;}
- *(output) = 0 ;
- strlcpy(outbuf, temp, length) ;
- return outbuf ;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement