Mercurial > mplayer.hg
changeset 33051:cec61c9f27f4
Simplify trim().
(A special return value for empty strings isn't needed.)
author | ib |
---|---|
date | Tue, 29 Mar 2011 08:15:01 +0000 |
parents | 36d0701bb4c8 |
children | 956c67bb5198 |
files | gui/util/string.c |
diffstat | 1 files changed, 12 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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 <stddef.h> -#include <string.h> - #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; }