Ignore:
Timestamp:
May 7, 2010, 6:49:10 PM (15 years ago)
Author:
herwigb
Message:

Split parameter string into separate parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0/src/utils.c

    r26 r30  
    88
    99/*  replace one string by another */
    10 BOOL searchReplace(const char *search, const char *replace, const char *string, char *replaced)
    11 {
    12         /* create init some variables */
    13         char *searchStart;
    14         int len = 0;
    15 
    16         /* do we find the searched string at all */
    17         searchStart = strstr(string, search);
    18         if (searchStart == NULL)
    19         {
    20                 strncpy(replaced, string, strlen(replaced));
    21                 return FALSE;
    22         }
    23 
    24         /* copy first part */
    25         len = searchStart - string;
    26         strncpy(replaced, string, len);
    27 
    28         /* add the replaced string */
    29         strcat(replaced, replace);
    30 
    31         /* add the last part */
    32         len += strlen(search);
    33         strcat(replaced, string+len);
    34 
    35         return TRUE;
     10BOOL searchReplace(const char *search, const char *replace, const char *string, char *replaced, int size)
     11{
     12// create/init some variables
     13        char *searchStart;
     14        char *p;
     15        int len = 0;
     16
     17// some sanity check
     18        if (replaced == NULL || replace == NULL)
     19        {
     20                return FALSE;
     21        }
     22
     23// do we find the searched string at all
     24        searchStart = strstr(string, search);
     25        if (searchStart == NULL)
     26        {
     27                strncpy(replaced, string, size);
     28                p = replaced+size;
     29                *p = '\0';
     30                return FALSE;
     31        }
     32
     33// copy first part
     34        len = searchStart - string;
     35        strncpy(replaced, string, len);
     36        p = replaced+len;
     37        *p = '\0';
     38
     39// add the replaced string
     40        strcat(replaced, replace);
     41
     42// add the last part
     43        len += strlen(search);
     44        strcat(replaced, string+len);
     45
     46        return TRUE;
     47}
     48
     49/* convert a string to uppercase */
     50void uppercase( char *sPtr )
     51{
     52        while( *sPtr != '\0' ) {
     53                *sPtr = toupper( ( unsigned char ) *sPtr );
     54        }
    3655}
    3756
Note: See TracChangeset for help on using the changeset viewer.