annotate gui/util/string.c @ 33049:fc7a3f9f74f8

Simplify strswap(). (A special return value for empty strings isn't needed.)
author ib
date Mon, 28 Mar 2011 16:03:26 +0000
parents c6d0adf896ea
children cec61c9f27f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
1 /*
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
2 * This file is part of MPlayer.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
3 *
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
7 * (at your option) any later version.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
8 *
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
12 * GNU General Public License for more details.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
13 *
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License along
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
17 */
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
18
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
19 #include <stddef.h>
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
20 #include <string.h>
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
21
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
22 #include "string.h"
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
23
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
24 char *strswap(char *in, char from, char to)
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
25 {
33049
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
26 char *p = in;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
27
33049
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
28 while (*p) {
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
29 if (*p == from)
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
30 *p = to;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
31
33049
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
32 p++;
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
33 }
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
34
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
35 return in;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
36 }
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
37
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
38 char *trim(char *in)
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
39 {
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
40 int c = 0, id = 0, i;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
41
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
42 if (!*in)
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
43 return NULL;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
44
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
45 while (c != (int)strlen(in)) {
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
46 if (in[c] == '"')
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
47 id = !id;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
48
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
49 if ((in[c] == ' ') && (!id)) {
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
50 for (i = 0; i < (int)strlen(in) - c; i++)
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
51 in[c + i] = in[c + i + 1];
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
52 continue;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
53 }
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
54
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
55 c++;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
56 }
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
57
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
58 return in;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
59 }