Changeset 3377

Show
Ignore:
Timestamp:
12/26/05 20:27:38 (3 years ago)
Author:
morris
Message:

Add support for WI_STRING_BACKWARDS flag in wi_string_index_of_char(), still need it in wi_string_index_of_string()

Fixes a bug where all path extensions where stripped in wire

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/data/wi-string.c

    r3355 r3377  
    812812void wi_string_delete_characters_in_range(wi_string_t *string, wi_range_t range) { 
    813813        _WI_STRING_INDEX_ASSERT(string, range.location + range.length); 
    814          
     814 
    815815        memmove(string->string + range.location, 
    816816                        string->string + range.location + range.length, 
     
    989989 
    990990 
    991 unsigned int wi_string_index_of_char(wi_string_t *string, char ch, wi_string_options_t options) { 
    992         char    *p; 
    993          
    994         p = (options & WI_STRING_BACKWARDS) 
    995                 ? strrchr(string->string, ch) 
    996                 : strchr(string->string, ch); 
    997          
    998         if(!p) 
    999                 return WI_NOT_FOUND; 
    1000          
    1001         return p - string->string; 
    1002 
    1003  
    1004  
     991unsigned int wi_string_index_of_char(wi_string_t *string, int ch, wi_string_options_t options) { 
     992        unsigned int    i, index = WI_NOT_FOUND; 
     993        char                    *p; 
     994        int                             c; 
     995        wi_boolean_t    insensitive = false; 
     996 
     997        if((options & WI_STRING_CASE_INSENSITIVE) || 
     998           (options & WI_STRING_SMART_CASE_INSENSITIVE && isupper(ch))) { 
     999                insensitive = true; 
     1000                ch = tolower((unsigned char) ch); 
     1001        } 
     1002 
     1003        p = string->string; 
     1004 
     1005        for(i = 0; *p; p++, i++) { 
     1006                c = insensitive ? tolower((unsigned char) *p) : *p; 
     1007 
     1008                if(c == ch) { 
     1009                        index = i; 
     1010 
     1011                        if(!(options & WI_STRING_BACKWARDS)) 
     1012                                break; 
     1013                } 
     1014        } 
     1015         
     1016        return index; 
     1017
     1018 
     1019  
    10051020 
    10061021wi_boolean_t wi_string_contains_string(wi_string_t *string, wi_string_t *otherstring, wi_string_options_t options) { 
     
    13111326        unsigned int    index; 
    13121327         
    1313         index = wi_string_index_of_string(path, WI_STR("."), WI_STRING_BACKWARDS); 
    1314          
     1328        index = wi_string_index_of_char(path, '.', WI_STRING_BACKWARDS); 
     1329 
    13151330        if(index != WI_NOT_FOUND) 
    13161331                wi_string_delete_characters_from_index(path, index); 
  • libwired/trunk/libwired/data/wi-string.h

    r3321 r3377  
    104104WI_EXPORT wi_range_t                                            wi_string_range_of_string(wi_string_t *, wi_string_t *, wi_string_options_t); 
    105105WI_EXPORT unsigned int                                          wi_string_index_of_string(wi_string_t *, wi_string_t *, wi_string_options_t); 
    106 WI_EXPORT unsigned int                                          wi_string_index_of_char(wi_string_t *, char, wi_string_options_t); 
     106WI_EXPORT unsigned int                                          wi_string_index_of_char(wi_string_t *, int, wi_string_options_t); 
    107107WI_EXPORT wi_boolean_t                                          wi_string_contains_string(wi_string_t *, wi_string_t *, wi_string_options_t); 
    108108WI_EXPORT wi_boolean_t                                          wi_string_has_prefix(wi_string_t *, wi_string_t *);