Changeset 3193 in MondoRescue for branches/3.2/mondo/src/lib/mr_str.c


Ignore:
Timestamp:
Sep 29, 2013, 9:31:34 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Finish with backports from 3.1 for now. Still some work to do, but we will now make that version compile and work again and serve as a base

so the gettext patch can be added

File:
1 edited

Legend:

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

    r3171 r3193  
    146146}
    147147
     148/* Return an allocated string containing the date
     149char *mr_date(void) {
     150   
     151    time_t tcurr;
     152    char *tmp = NULL;
     153
     154    tcurr = time(NULL);
     155    mr_asprintf(tmp, "%s", ctime(&tcurr));
     156    mr_chomp(tmp);
     157    return(tmp);
     158}
     159 */
    148160
    149161/**
     
    181193    in_out[i] = '\0';
    182194}
     195
     196
     197/*
     198 * Remove '\n' char from both sides of @p in_out.
     199 * @param in_out The string to strip characters from (modified).
     200
     201void mr_chomp(char *in_out) {
     202
     203    mr_strip_char(in_out, "\n");
     204}
     205*/
     206
     207/**
     208 * Remove all characters in caracs from begining and end of string @p in_out
     209 * @param in_out The string to strip char characters from (modified).
     210
     211void mr_strip_char(char *in_out, char *caracs) {
     212    int i = 0;
     213    int j = 0;
     214    size_t length = 0;
     215
     216    if (caracs == NULL) {
     217        return;
     218    }
     219    if (in_out == NULL) {
     220        return;
     221    }
     222    length = strlen(in_out);
     223
     224    /* Skip initial caracs */
     225    for (i = 0; index(caracs, in_out[i]) != NULL && i < (int)length ; i++);
     226
     227    /* Shift the string to the begining if needed */
     228    if (i != 0) {
     229        for (j = 0; i < (int)length ; i++, j++) {
     230            in_out[j] = in_out[i];
     231        }
     232        /* Erase the end of the string if needed */
     233        j++;
     234        in_out[j] = '\0';
     235    }
     236
     237    /* Skip final caracs */
     238    for (i = (int)strlen(in_out) - 1; i >= 0  && index(caracs, in_out[i]) != NULL; i--);
     239
     240    /* The string now ends after that char */
     241    i++;
     242    in_out[i] = '\0';
     243}
     244*/
     245
Note: See TracChangeset for help on using the changeset viewer.