Changeset 5602:6d421545ca98 in roaraudio for libroar


Ignore:
Timestamp:
07/30/12 16:59:54 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

moved strselcmp() and strseltok() to libroar (Closes: #285)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/memmgr.c

    r5381 r5602  
    416416#endif 
    417417 
     418int roar_mm_strselcmp(const char *s1, const char *s2) { 
     419 register char a, b; 
     420 
     421 if ( s1 == s2 ) 
     422  return 0; 
     423 
     424 if ( s1 == NULL || s2 == NULL ) 
     425  return -1; 
     426 
     427 for (; ; s1++, s2++) { 
     428  a = *s1; 
     429  b = *s2; 
     430 
     431  if ( a == '*' ) { 
     432   s1++; 
     433   a = *s1; 
     434   if ( a == 0 ) { 
     435    if ( b == 0 ) { 
     436     return 1; // no match! ('*' does not mach no-chars) 
     437    } else { 
     438     return 0; // match! (string ends with '*' and something not EOS is in b) 
     439    } 
     440   } else { 
     441    for (; *s2 != 0 && *s2 != a; s2++); 
     442    if ( a != *s2 ) 
     443     return 1; // no match! (did not find correct char) 
     444   } 
     445  } else if ( a == 0 || b == 0 ) { 
     446   if ( a == b ) { 
     447    return 0; // match! 
     448   } else { 
     449    return 1; // no match! (dffrent length) 
     450   } 
     451  } else if ( a != b ) { 
     452   return 1; // no match! (diffrent chars) 
     453  } 
     454 } 
     455 
     456 return -1; 
     457} 
     458 
     459ssize_t roar_mm_strseltok(const char *s1, char *s2, char ** tok, size_t toks) { 
     460 register char a, b; 
     461 size_t idx = 0; 
     462 
     463 if ( s1 == NULL || s2 == NULL ) 
     464  return -1; 
     465 
     466 for (; ; s1++, s2++) { 
     467  a = *s1; 
     468  b = *s2; 
     469 
     470  if ( a == 0 || b == 0 ) { 
     471   if ( a == b ) { 
     472    return idx; 
     473   } else { 
     474    return -1; 
     475   } 
     476  } else if ( a == '*' ) { 
     477   s1++; 
     478   a = *s1; 
     479   if ( idx == toks ) 
     480    return -1; 
     481 
     482   tok[idx] = s2; 
     483   idx++; 
     484 
     485   for (; *s2 != 0 && *s2 != a; s2++); 
     486 
     487   if ( a == 0 ) 
     488    return idx; 
     489 
     490   if ( *s1 == 0 ) 
     491    return -1; 
     492 
     493   *s2 = 0; 
     494  } 
     495 } 
     496 
     497 return -1; 
     498} 
     499 
    418500//ll 
Note: See TracChangeset for help on using the changeset viewer.