--- rxvt-unicode/src/misc.C 2004/12/13 07:26:18 1.21 +++ rxvt-unicode/src/misc.C 2005/02/07 01:17:03 1.25 @@ -38,7 +38,7 @@ char *dst = r; while (len--) { - int l = wcrtomb (dst, *str++, mbs); + ssize_t l = wcrtomb (dst, *str++, mbs); if (l < 0) *dst++ = '?'; else @@ -47,7 +47,7 @@ *dst++ = 0; - return r; + return (char *)rxvt_realloc (r, dst - r); } wchar_t * @@ -57,7 +57,7 @@ wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)); - if (mbstowcs (r, str, len + 1) < 0) + if ((ssize_t)mbstowcs (r, str, len + 1) < 0) *r = 0; return r; @@ -73,7 +73,7 @@ while (len--) { - unicode_t w = *str++; + unicode_t w = *str++ & UNICODE_MASK; if (w < 0x000080) *p++ = w; @@ -93,9 +93,9 @@ *p++ = '?'; } - *p = 0; + *p++ = 0; - return r; + return (char *)rxvt_realloc (r, p - r); } wchar_t * @@ -284,32 +284,31 @@ rxvt_Str_trim (char *str) { char *r, *s; - int n; if (!str || !*str) /* shortcut */ return str; /* skip leading spaces */ for (s = str; *s && isspace (*s); s++) ; + /* goto end of string */ - for (n = 0, r = s; *r++; n++) ; - r -= 2; - /* dump return */ - if (n > 0 && *r == '\n') - n--, r--; - /* backtrack along trailing spaces */ - for (; n > 0 && isspace (*r); r--, n--) ; + r = s + strlen (s) - 1; + + /* dump return and other trailing whitespace */ + while (r > s && isspace (*r)) + r--; + +#if 0 /* skip matching leading/trailing quotes */ if (*s == '"' && *r == '"' && n > 1) { s++; n -= 2; } +#endif - /* copy back over: forwards copy */ - for (r = str; n; n--) - *r++ = *s++; - *r = '\0'; + memmove (str, s, r + 1 - s); + str[r + 1 - s] = 0; return str; } @@ -402,8 +401,7 @@ /* * Split a comma-separated string into an array, stripping leading and - * trailing spaces (and paired quotes) from each entry. Empty strings - * are properly returned + * trailing spaces from each entry. Empty strings are properly returned * Caller should free each entry and array when done */ /* INTPROTO */ @@ -420,6 +418,7 @@ for (n = 1, t = s; *t; t++) if (*t == ',') n++; + ret = (char **)malloc ((n + 1) * sizeof (char *)); ret[n] = NULL; @@ -433,6 +432,7 @@ rxvt_Str_trim (ret[l]); s = ++t; } + return ret; }