Changeset 2421 in MondoRescue for branches/2.2.10/mondo/src/lib/mr_str.c
- Timestamp:
- Sep 24, 2009, 3:50:38 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/lib/mr_str.c
r1924 r2421 104 104 } 105 105 106 /* Return a string containing the date */107 char *mr_date(void) {108 109 time_t tcurr;110 111 tcurr = time(NULL);112 return(ctime(&tcurr));113 }114 115 116 106 /** 117 * Remove all characters whose ASCII value is less than or equal to 32 118 * (spaces and control characters) from both sides of @p in_out. 119 * @param in_out The string to strip spaces/control characters from (modified). 107 * Remove all characters in caracs from begining and end of string @p in_out 108 * @param in_out The string to strip char characters from (modified). 120 109 */ 121 void mr_strip_ spaces(char *in_out) {110 void mr_strip_char(char *in_out, char *caracs) { 122 111 int i = 0; 123 112 int j = 0; 124 size_t length;113 int length = 0; 125 114 115 if (caracs == NULL) { 116 return; 117 } 126 118 if (in_out == NULL) { 127 119 return; 128 120 } 129 length = strlen(in_out);121 length = (int)strlen(in_out); 130 122 131 /* Skip initial spaces and special chars */ 132 for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++); 123 /* Skip initial caracs */ 124 for (i = 0; index(caracs, in_out[i]) != NULL && i < length ; i++); 125 133 126 /* Shift the string to the begining if needed */ 134 127 if (i != 0) { 135 for (j = 0; i < (int)length ; i++, j++) {128 for (j = 0; i < length ; i++, j++) { 136 129 in_out[j] = in_out[i]; 137 130 } … … 142 135 143 136 /* Skip final spaces and special chars */ 144 for (i = (int)strlen(in_out) - 1; i >= 0 && in _out[i] <= ' '; i--);137 for (i = (int)strlen(in_out) - 1; i >= 0 && index(caracs, in_out[i]) != NULL; i--); 145 138 146 139 /* The string now ends after that char */ … … 148 141 in_out[i] = '\0'; 149 142 } 143 144 /** 145 * Remove all characters whose ASCII value is less than or equal to 32 146 * (spaces and control characters) from both sides of @p in_out. 147 * @param in_out The string to strip spaces/control characters from (modified). 148 */ 149 void mr_strip_spaces(char *in_out) { 150 151 int i; 152 char *tmp = NULL; 153 154 mr_asprintf(tmp, ""); 155 156 /* Build the string of char to avoid: ctrl char up to space*/ 157 for (i = 0; i <= ' '; i++) { 158 mr_strcat(tmp, "%c", i); 159 } 160 161 mr_strip_char(in_out, tmp); 162 mr_free(tmp); 163 } 164 165 /* 166 * Remove '\n' char from both sides of @p in_out. 167 * @param in_out The string to strip characters from (modified). 168 */ 169 void mr_chomp(char *in_out) { 170 171 mr_strip_char(in_out, "\n"); 172 } 173 174 /* Return an allocated string containing the date */ 175 char *mr_date(void) { 176 177 time_t tcurr; 178 char *tmp = NULL; 179 180 tcurr = time(NULL); 181 mr_asprintf(tmp, "%s", ctime(&tcurr)); 182 mr_chomp(tmp); 183 return(tmp); 184 } 185 186
Note:
See TracChangeset
for help on using the changeset viewer.