| version 1.5, 2001/12/08 18:23:53 |
version 1.6, 2001/12/09 15:06:35 |
|
|
| #include <string.h> |
#include <string.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <ctype.h> |
#include <ctype.h> |
| |
#include <stdio.h> |
| |
|
| #include "strplus.h" |
#include "strplus.h" |
| #include "strctype.h" |
#include "strctype.h" |
| Line 121 char *str_left_trim(char *s) |
|
| Line 122 char *str_left_trim(char *s) |
|
| { |
{ |
| register char *pos; |
register char *pos; |
| |
|
| for (pos = s; *pos != '\0' && isspace(*pos); pos++) |
for (pos = s; *pos != '\0' && isspace(*pos); pos++) ; |
| ; |
|
| |
|
| if (pos > s) |
if (pos > s) |
| memmove((void *) s, (void *) pos, strlen(pos) + 1); |
memmove((void *) s, (void *) pos, strlen(pos) + 1); |
| Line 134 char *str_right_trim(char *s) |
|
| Line 134 char *str_right_trim(char *s) |
|
| { |
{ |
| register char *pos; |
register char *pos; |
| |
|
| for (pos = s + (strlen(s) - 1); pos >= s && isspace(*pos); pos--) |
for (pos = s + (strlen(s) - 1); pos >= s && isspace(*pos); pos--) ; |
| ; |
|
| |
|
| *(pos + 1) = '\0'; |
*(pos + 1) = '\0'; |
| |
|
| return s; |
return s; |
| } |
} |
| |
|
| |
char *str_trim_whitechars(char *s) |
| |
{ |
| |
register char *pos, *start; |
| |
|
| |
for (pos = s, start = NULL; ; pos++) { |
| |
if (isspace(*pos)) { |
| |
if (start == NULL) |
| |
start = pos; |
| |
} |
| |
else { |
| |
if (start != NULL) { |
| |
memmove(start + 1, pos, strlen(pos) + 1); |
| |
*start = ' '; |
| |
|
| |
pos = start + 1; |
| |
start = NULL; |
| |
} |
| |
} |
| |
|
| |
if (*pos == '\0') |
| |
break; |
| |
} |
| |
|
| |
return s; |
| |
} |
| |
|
| int strrcmp(const char *s1, const char *s2) |
int strrcmp(const char *s1, const char *s2) |
| { |
{ |
| register char *x1, *x2; |
register char *x1, *x2; |
| Line 167 int strrcmp(const char *s1, const char * |
|
| Line 192 int strrcmp(const char *s1, const char * |
|
| #define TESTSEP1 '_' |
#define TESTSEP1 '_' |
| #define TESTSEP2 "BB" |
#define TESTSEP2 "BB" |
| |
|
| int main(void) { |
#define TESTSTR2 " \t AAA\nBBBB__C D\taDa D \t \t" |
| |
|
| |
int main(void) |
| |
{ |
| |
char *str2 = strdup(TESTSTR2); |
| |
|
| printf("strcnt(\"%s\", '%c') = %d\n", |
printf("strcnt(\"%s\", '%c') = %d\n", |
| TESTSTR1, TESTSEP1, |
TESTSTR1, TESTSEP1, |
| Line 181 int main(void) { |
|
| Line 210 int main(void) { |
|
| TESTSTR1, TESTSEP2, |
TESTSTR1, TESTSEP2, |
| strcnt_sepstr(TESTSTR1, TESTSEP2)); |
strcnt_sepstr(TESTSTR1, TESTSEP2)); |
| |
|
| |
printf("str_trim_whitechars(\"%s\") = \"%s\"\n", |
| |
TESTSTR2, str_trim_whitechars(str2)); |
| |
|
| |
free(str2); |
| |
|
| return 0; |
return 0; |
| } |
} |
| |
|