-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.h
72 lines (62 loc) · 1.84 KB
/
utils.h
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
#ifndef _UTILS_H
#define _UTILS_H
/**
* Utils module
*/
/**
* absolute value for integer
*/
int util_abs(int);
/**
* Trim a string (remove extra spaces around words)
* @return the trimed string
*/
extern char* str_trim(char *s);
/**
* Truncate a string str by a maximum length
*/
extern void str_truncate(char* str, int length);
/**
* Format a string str with only alphanumeric
* by replacing all others characters by underscores
*/
extern void str_formatOnlyAlphaAndUnderscore(char* str);
/// Args utils ///
/**
* Check if argv contains key
* @param argv, argc : given from the main()
* @param key : the string to search
* @return
* 1: if argv contains the string key
* 0: else
*/
extern int util_containsArg(int argc, char * argv[], char* key);
/**
* Get an integer from argv following the key arg
* example : ./prog arg1 arg2 --level 8 arg3 ...
* The function will also consume args '--level' and '8'.
*
* @param argv, argc : given from the main()
* @param key : the key to search (preceding the value)
* @param value : the dest value getted after the arg key
* @return a status:
* 0: arg successfully getted
* 1: arg was not found in argv
* 2: no digits were found in the string
* 3: the arg value is invalid
*/
extern int util_getArgValue(int argc, char * argv[], char * key, int * value);
/**
* Get a string arg following the key arg from argv
* example : ./prog arg1 arg2 -d dictionaries/fr.txt arg3 ...
* The function will also consume taken args ('-d' and 'dictionaries/fr.txt').
*
* @param argv, argc : given from the main()
* @param key : the key to search (preceding the value)
* @param value : the dest value getted after the arg key
* @return a status:
* 0: arg successfully getted
* 1: arg was not found in argv
*/
extern int util_getArgString(int argc, char * argv[], char * key, char** value);
#endif