lib/cfg_parse.c
/* Returns a duplicate of input str, without leading / trailing whitespace
    Input str *MUST* be null-terminated, or disaster will result */
Returns a duplicate of input str, without leading / trailing whitespace
Input str *MUST* be null-terminated, or disaster will result
Returns a duplicate of input str without leading / trailing whitespace Input str * MUST * be null - terminated or disaster will result
static char *cfg_trim(const char *str)
{
  int temp_len;
  char *tstr;
  if (str == NULL) return NULL;
  while (cfg_is_whitespace(*str))
    str ++;
  temp_len = strlen(str);
  while (temp_len > 0 && cfg_is_whitespace(str[temp_len-1]))
    temp_len --;
  tstr = (char *)cfg_malloc(temp_len + 1);
  memcpy(tstr,str,temp_len);
  return tstr;
}
static char * cfg_trim ( const char * str ) { int temp_len ; char * tstr ; if ( str == NULL ) return NULL ; while ( cfg_is_whitespace ( * str ) ) str ++ ; temp_len = strlen ( str ) ; while ( temp_len > 0 && cfg_is_whitespace ( str [ temp_len - 1 ] ) ) temp_len -- ; tstr = ( char * ) cfg_malloc ( temp_len + 1 ) ; memcpy ( tstr , str , temp_len ) ; return tstr ; }
Returns a duplicate of input str, without leading / trailing whitespace
Input str *MUST* be null-terminated, or disaster will result
Returns a duplicate of input str without leading / trailing whitespace Input str * MUST * be null - terminated or disaster will result
/* check for null input first */ /* advance start pointer to first non-whitespace char */ /* calculate length of output string, minus leading whitespace */ /* roll back length until we run out of whitespace */ /* copy portion of string to new string */