Mercurial > mplayer.hg
comparison gui/util/string.c @ 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 | fc7a3f9f74f8 |
children | 956c67bb5198 |
comparison
equal
deleted
inserted
replaced
33050:36d0701bb4c8 | 33051:cec61c9f27f4 |
---|---|
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License along | 14 * You should have received a copy of the GNU General Public License along |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | 15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 */ | 17 */ |
18 | |
19 #include <stddef.h> | |
20 #include <string.h> | |
21 | 18 |
22 #include "string.h" | 19 #include "string.h" |
23 | 20 |
24 char *strswap(char *in, char from, char to) | 21 char *strswap(char *in, char from, char to) |
25 { | 22 { |
35 return in; | 32 return in; |
36 } | 33 } |
37 | 34 |
38 char *trim(char *in) | 35 char *trim(char *in) |
39 { | 36 { |
40 int c = 0, id = 0, i; | 37 char *src, *dest; |
38 int freeze = 0; | |
41 | 39 |
42 if (!*in) | 40 src = dest = in; |
43 return NULL; | |
44 | 41 |
45 while (c != (int)strlen(in)) { | 42 while (*src) { |
46 if (in[c] == '"') | 43 if (*src == '"') |
47 id = !id; | 44 freeze = !freeze; |
48 | 45 |
49 if ((in[c] == ' ') && (!id)) { | 46 if (freeze || (*src != ' ')) |
50 for (i = 0; i < (int)strlen(in) - c; i++) | 47 *dest++ = *src; |
51 in[c + i] = in[c + i + 1]; | |
52 continue; | |
53 } | |
54 | 48 |
55 c++; | 49 src++; |
56 } | 50 } |
51 | |
52 *dest = 0; | |
57 | 53 |
58 return in; | 54 return in; |
59 } | 55 } |