-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_utils.c
79 lines (70 loc) · 1.47 KB
/
string_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdlib.h>
#include <string.h>
#include <libavutil/avstring.h>
#define SPACE_CHARS " \t\r\n"
static void get_word_until_chars(char *buf, int buf_size,
char *sep, const char **pp)
{
const char *p;
char *q;
p = *pp;
p += strspn(p, SPACE_CHARS);
q = buf;
while (!strchr(sep, *p) && *p != '\0') {
if ((q - buf) < buf_size - 1)
*q++ = *p;
p++;
}
if (buf_size > 0)
*q = '\0';
*pp = p;
}
void get_word_sep(char *buf, int buf_size, char *sep,
const char **pp)
{
if (**pp == '/') (*pp)++;
get_word_until_chars(buf, buf_size, sep, pp);
}
static void skip_spaces(const char **pp)
{
const char *p;
p = *pp;
while (*p == ' ' || *p == '\t')
p++;
*pp = p;
}
void get_word(char *buf, int buf_size, const char **pp)
{
const char *p;
char *q;
p = *pp;
skip_spaces(&p);
q = buf;
while (!av_isspace(*p) && *p != '\0') {
if ((q - buf) < buf_size - 1)
*q++ = *p;
p++;
}
if (buf_size > 0)
*q = '\0';
*pp = p;
}
void parse_range(int *min_ptr, int *max_ptr, const char **pp)
{
const char *q;
char *p;
int v;
q = *pp;
q += strspn(q, SPACE_CHARS);
v = strtol(q, &p, 10);
if (*p == '-') {
p++;
*min_ptr = v;
v = strtol(p, &p, 10);
*max_ptr = v;
} else {
*min_ptr = v;
*max_ptr = v;
}
*pp = p;
}