33046
|
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 */
|
|
18
|
33981
|
19 /**
|
|
20 * @file
|
|
21 * @brief Parser helpers
|
|
22 */
|
|
23
|
33046
|
24 #include <stdlib.h>
|
|
25 #include <string.h>
|
|
26
|
|
27 #include "cut.h"
|
|
28
|
33981
|
29 /**
|
|
30 * @brief Extract a part of a string delimited by a separator character.
|
|
31 *
|
|
32 * @param in string to be analyzed
|
|
33 * @param out pointer suitable to store the extracted part
|
|
34 * @param sep separator character
|
|
35 * @param num number of separator characters to be skipped before extraction starts
|
|
36 * @param maxout maximum length of extracted part (including the trailing null byte)
|
|
37 */
|
33046
|
38 void cutItemString(char *in, char *out, char sep, int num, size_t maxout)
|
|
39 {
|
|
40 int n;
|
|
41 unsigned int i, c;
|
|
42
|
|
43 for (c = 0, n = 0, i = 0; in[i]; i++) {
|
|
44 if (in[i] == sep)
|
|
45 n++;
|
|
46 if (n >= num && in[i] != sep && c + 1 < maxout)
|
|
47 out[c++] = in[i];
|
|
48 if (n >= num && in[i + 1] == sep)
|
|
49 break;
|
|
50 }
|
|
51
|
|
52 if (c < maxout)
|
|
53 out[c] = 0;
|
|
54 }
|
|
55
|
33981
|
56 /**
|
|
57 * @brief Extract a numeric part of a string delimited by a separator character.
|
|
58 *
|
|
59 * @param in string to be analyzed
|
|
60 * @param sep separator character
|
|
61 * @param num number of separator characters to be skipped before extraction starts
|
|
62 *
|
|
63 * @return extracted number (numeric part)
|
|
64 */
|
33046
|
65 int cutItemToInt(char *in, char sep, int num)
|
|
66 {
|
|
67 char tmp[64];
|
|
68
|
|
69 cutItem(in, tmp, sep, num);
|
33053
|
70
|
33046
|
71 return atoi(tmp);
|
|
72 }
|