# HG changeset patch # User ib # Date 1301386501 0 # Node ID cec61c9f27f4b80efb6cdca876eb17947169d548 # Parent 36d0701bb4c869a662638c76b1b3eb4b94e77de7 Simplify trim(). (A special return value for empty strings isn't needed.) diff -r 36d0701bb4c8 -r cec61c9f27f4 gui/util/string.c --- a/gui/util/string.c Mon Mar 28 22:18:56 2011 +0000 +++ b/gui/util/string.c Tue Mar 29 08:15:01 2011 +0000 @@ -16,9 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include - #include "string.h" char *strswap(char *in, char from, char to) @@ -37,23 +34,22 @@ char *trim(char *in) { - int c = 0, id = 0, i; + char *src, *dest; + int freeze = 0; - if (!*in) - return NULL; - - while (c != (int)strlen(in)) { - if (in[c] == '"') - id = !id; + src = dest = in; - if ((in[c] == ' ') && (!id)) { - for (i = 0; i < (int)strlen(in) - c; i++) - in[c + i] = in[c + i + 1]; - continue; - } + while (*src) { + if (*src == '"') + freeze = !freeze; - c++; + if (freeze || (*src != ' ')) + *dest++ = *src; + + src++; } + *dest = 0; + return in; }