Advertisement
NovaYoshi

awful C

Aug 12th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. char *sanitize_name(char *outbuf, const char *input, int length)     {
  2.   char hex[3]                                                        ;
  3.   char temp[strlen(input)*2+1]                                       ;
  4.   char *output = temp                                                ;
  5.  
  6.   if(!isalpha(*input) && *input != '_')
  7.     *(output++) = '_';
  8.   while(*input)                                                      {
  9.     if(isalnum(*input))
  10.       *(output++) = *input                                           ;
  11.     else if(*input == ' ' || *input == '-')                          {
  12.       *(output++) = '_'                                              ;}
  13.     else                                                             {
  14.       sprintf(hex, "%.2x", *input)                                   ;
  15.       strcpy(output, hex)                                            ;
  16.       output += 2                                                    ;}
  17.     input++                                                          ;}
  18.   *(output) = 0                                                      ;
  19.  
  20.   strlcpy(outbuf, temp, length)                                      ;
  21.   return outbuf                                                      ;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement