-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr.c
More file actions
48 lines (38 loc) · 720 Bytes
/
str.c
File metadata and controls
48 lines (38 loc) · 720 Bytes
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
#include <ctype.h>
#include <stddef.h>
#include <string.h>
size_t
eat_ident(char *buffer, size_t length)
{
size_t offset=0;
char *comment;
if (!length) return 0;
comment = memchr(buffer, '#', length);
if (comment) length = comment - buffer;
while (!isspace(buffer[offset])) {
if (++offset >= length) {
return offset;
}
}
return offset;
}
size_t
eat_spaces(char *buffer, size_t length)
{
size_t offset=0;
char *nl;
if (!length) return 0;
again:
while (isspace(buffer[offset])) {
if (++offset >= length) {
return offset;
}
}
if (buffer[offset] == '#') {
nl = memchr(buffer+offset, '\n', length);
if (!nl) return length;
offset = nl - buffer;
goto again;
}
return offset;
}