Changeset 5482:ba865ae62928 in roaraudio for libroar/keyval.c


Ignore:
Timestamp:
04/25/12 09:46:25 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support quoted strings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/keyval.c

    r5381 r5482  
    6565} 
    6666 
     67static inline void skip_char(char * str) { 
     68 memmove(str, str+1, roar_mm_strlen(str)); 
     69} 
     70 
    6771ssize_t              roar_keyval_split  (struct roar_keyval ** kv, char * str, const char * fdel, const char * kdel, int quotes) { 
    6872 struct roar_keyval * kvs; 
     
    7579 if ( kv == NULL || str == NULL ) { 
    7680  roar_err_set(ROAR_ERROR_FAULT); 
    77   return -1; 
    78  } 
    79  
    80  // we currently do not support quotes 
    81  if ( quotes ) { 
    82   roar_err_set(ROAR_ERROR_NOTSUP); 
    8381  return -1; 
    8482 } 
     
    9593   if ( *sp == quote ) 
    9694    quote = 0; 
     95  } else if ( quotes && (*sp == '\'' || *sp == '\"') ) { 
     96   quote = *sp; 
    9797  } else { 
    9898   if ( last_was_seg ) { 
     
    122122 
    123123 for (sp = str; *sp != 0; sp++) { 
     124  if ( quote ) { 
     125   if ( *sp == quote ) { 
     126    skip_char(sp); 
     127    quote = 0; 
     128   } else { 
     129    continue; 
     130   } 
     131  } else if ( quotes && (*sp == '\'' || *sp == '\"') ) { 
     132   quote = *sp; 
     133   skip_char(sp); 
     134   continue; 
     135  } 
     136 
    124137  if ( last_was_seg ) { 
    125138   if ( is_in(*sp, fdel) ) { 
     
    128141   } else { 
    129142    last_was_seg = 1; 
    130     if ( is_in(*sp, kdel) ) { 
     143    if ( kvs[pos].value == NULL && is_in(*sp, kdel) ) { 
    131144     *sp = 0; 
    132145     kvs[pos].value = sp+1; 
Note: See TracChangeset for help on using the changeset viewer.