{
const char *sp = str;
char *p, *s = NULL;
+ size_t len;
- if (!sp)
- return NULL;
+ if (zstr(sp)) {
+ return (char *) sp;
+ }
while ((*sp == 13 ) || (*sp == 10 ) || (*sp == 9 ) || (*sp == 32) || (*sp == 11) ) {
sp++;
}
+
+ if (zstr(sp)) {
+ return (char *) sp;
+ }
s = strdup(sp);
+ switch_assert(s);
- if (!s)
- return NULL;
-
- p = s + (strlen(s) - 1);
+ if ((len = strlen(s)) > 0) {
+ p = s + (len - 1);
- while ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11) ) {
- *p-- = '\0';
+ while (p > s && ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11))) {
+ *p-- = '\0';
+ }
}
return s;
{
char *sp = str;
char *p, *s = NULL;
+ size_t len;
- if (!sp)
- return NULL;
+ if (zstr(sp)) {
+ return sp;
+ }
while (*sp == ' ') {
sp++;
if (dup) {
s = strdup(sp);
+ switch_assert(s);
} else {
s = sp;
}
- if (!s)
- return NULL;
+ if (zstr(s)) {
+ return s;
+ }
- p = s + (strlen(s) - 1);
+ if ((len = strlen(s)) > 0) {
+ p = s + (len - 1);
- while (*p == ' ') {
- *p-- = '\0';
+ while (p && *p && p > s && *p == ' ') {
+ *p-- = '\0';
+ }
}
return s;