|
version 1.9, 2005/01/14 01:50:03
|
version 1.10, 2006/02/13 01:14:59
|
|
|
|
| /* $XTermId: xstrings.c,v 1.21 2005/01/11 00:13:47 tom Exp $ */ |
/* $XTermId: xstrings.c,v 1.24 2006/01/29 22:34:04 tom Exp $ */ |
| | |
| /* $XFree86: xc/programs/xterm/xstrings.c,v 1.8 2004/12/01 01:27:47 dickey Exp $ */ |
/* $XFree86: xc/programs/xterm/xstrings.c,v 1.9 2005/01/14 01:50:03 dickey Exp $ */ |
| | |
| /************************************************************ | /************************************************************ |
| | |
| Copyright 2000-2004,2005 by Thomas E. Dickey |
Copyright 2000-2005,2006 by Thomas E. Dickey |
| | |
| All Rights Reserved | All Rights Reserved |
| | |
|
|
|
| return (cp ? cp + 1 : name); | return (cp ? cp + 1 : name); |
| } | } |
| | |
| |
char * |
| |
x_skip_blanks(char *s) |
| |
{ |
| |
while (isspace(CharOf(*s))) |
| |
++s; |
| |
return s; |
| |
} |
| |
|
| |
char * |
| |
x_skip_nonblanks(char *s) |
| |
{ |
| |
while (*s != '\0' && !isspace(CharOf(*s))) |
| |
++s; |
| |
return s; |
| |
} |
| |
|
| int | int |
| x_strcasecmp(const char *s1, const char *s2) | x_strcasecmp(const char *s1, const char *s2) |
| { | { |
|
|
|
| if (len != strlen(s2)) | if (len != strlen(s2)) |
| return 1; | return 1; |
| | |
| while (len-- != 0) { |
return x_strncasecmp(s1, s2, len); |
| |
} |
| |
|
| |
int |
| |
x_strncasecmp(const char *s1, const char *s2, unsigned n) |
| |
{ |
| |
while (n-- != 0) { |
| int c1 = toupper(CharOf(*s1)); | int c1 = toupper(CharOf(*s1)); |
| int c2 = toupper(CharOf(*s2)); | int c2 = toupper(CharOf(*s2)); |
| if (c1 != c2) | if (c1 != c2) |
| return 1; | return 1; |
| |
if (c1 == 0) |
| |
break; |
| s1++, s2++; | s1++, s2++; |
| } | } |
| | |
|
|
|
| } | } |
| | |
| /* | /* |
| * Trims leading/trailing spaces from the string, returns a copy of it if it |
* Trims leading/trailing spaces from a copy of the string. |
| * is modified. |
|
| */ | */ |
| char * | char * |
| x_strtrim(char *s) | x_strtrim(char *s) |
|
|
|
| char *t = x_strdup(base); | char *t = x_strdup(base); |
| s = t; | s = t; |
| d = s; | d = s; |
| while (isspace(CharOf(*s))) { |
s = x_skip_blanks(s); |
| ++s; |
|
| } |
|
| while ((*d++ = *s++) != '\0') { | while ((*d++ = *s++) != '\0') { |
| ; | ; |
| } | } |
|
|
|
| *--s = '\0'; | *--s = '\0'; |
| } | } |
| } | } |
| if (!strcmp(t, base)) { |
|
| free(t); |
|
| } else { |
|
| base = t; | base = t; |
| } |
|
| } | } |
| return base; | return base; |
| } | } |