- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
Latest commit
36 lines (27 loc) · 1.25 KB
/
Copy pathutil.h
File metadata and controls
36 lines (27 loc) · 1.25 KB
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
#ifndefUTIL_H
#defineUTIL_H
#include<stddef.h>
//returns index of first occurance of c or -1 or c is not in string
intfind_first(constchar*line, charc);
//replaces trailing newline (CRLF or LF) with null terminator
//assumes that line[len] is the null terminator and that string
//actually ends with newline (ie: line[len - 1] == '\n')
voidremove_endline(char*line, size_tlen);
//checks if c is one of ' ' \r \t \t \0
intis_trailing_space(charc);
//remove trailing whitespace (ie: ' ' \t \r \n)
voidremove_trailing_whitespace(char*line, size_tlen);
//removes leading and trailing whitespace and returns pointer to
//beginning of trimmed line
char*strip(char*line);
//parses unsigned decimal number, returns -1 on invalid digit string
intparse_uint(constchar*num_str);
//takes comma seperated list of elements calls handle_elt for each element
//-leading and trailing whitespace is removed from each element
//-the args parameter for handler allows handler to use extra state
//handle_elt should return -1 on error
//returns -1 if handle_elt returns an error for any list element
//returns number of elements otherwise
//TODO: make element delimeter a parameter
intparse_list(char*list, int (*handle_elt)(char*elt, void*args), void*args);
#endif