26458
|
1 /*
|
|
2 * This file is part of MPlayer.
|
|
3 *
|
|
4 * MPlayer is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * MPlayer is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
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.,
|
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
17 */
|
23077
|
18
|
32868
|
19 #include <stdlib.h>
|
23077
|
20 #include <string.h>
|
|
21
|
30529
|
22 #include "cut.h"
|
|
23
|
32868
|
24 void cutItemString(char *in, char *out, char sep, int num, size_t maxout)
|
23077
|
25 {
|
32868
|
26 int n;
|
|
27 unsigned int i, c;
|
|
28
|
|
29 for (c = 0, n = 0, i = 0; i < strlen(in); i++) {
|
|
30 if (in[i] == sep)
|
|
31 n++;
|
|
32 if (n >= num && in[i] != sep && c + 1 < maxout)
|
|
33 out[c++] = in[i];
|
|
34 if (n >= num && in[i + 1] == sep)
|
|
35 break;
|
|
36 }
|
|
37
|
|
38 if (c < maxout)
|
|
39 out[c] = 0;
|
23077
|
40 }
|
|
41
|
32868
|
42 int cutItemToInt(char *in, char sep, int num)
|
23077
|
43 {
|
32868
|
44 char tmp[64];
|
|
45
|
|
46 cutItem(in, tmp, sep, num);
|
|
47 return atoi(tmp);
|
23077
|
48 }
|