Changeset 1168 in MondoRescue for branches/stable/mondo/src/lib/mr_str.c


Ignore:
Timestamp:
Feb 15, 2007, 12:27:39 AM (17 years ago)
Author:
Bruno Cornec
Message:

strip_spaces => mr_strip_spaces in mr_str.c and corrected at the same time :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/lib/mr_str.c

    r1087 r1168  
    116116}
    117117
     118
     119/**
     120 * Remove all characters whose ASCII value is less than or equal to 32
     121 * (spaces and control characters) from both sides of @p in_out.
     122 * @param in_out The string to strip spaces/control characters from (modified).
     123 */
     124void mr_strip_spaces(char *in_out)
     125{
     126    /*@ int ******************************************************** */
     127    int i;
     128    int j;
     129    size_t length;
     130
     131    /*@ end vars *************************************************** */
     132
     133    if (in_out == NULL) {
     134        return;
     135    }
     136    length = strlen(in_out);
     137
     138    /* Skip initial spaces and special chars */
     139    for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++);
     140    /* Shift the string to the begining */
     141    for (j = 0; i < (int)length ; i++, j++) {
     142        in_out[j] = in_out[i];
     143    }
     144    /* Skip final spaces and special chars */
     145    for (i = (int)strlen(in_out) - 1; in_out[i] <= ' ' && i >= 0 ; i--);
     146
     147    /* The string now ends after that char */
     148    i++;
     149    in_out[i] = '\0';
     150}
Note: See TracChangeset for help on using the changeset viewer.