-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.h
61 lines (51 loc) · 1.24 KB
/
util.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
/* util.h
*
* Some useful functions and structs.
*/
#ifndef __regex_util
#define __regex_util
#include <stdbool.h>
#include <stdint.h>
/* The following structs hold a range of 16-bit ints and 32-bit ints
* respectively. These are used to keep track of unicode tables and
* the 32-bit range is used in the implementation of class_t.
*/
typedef struct {
uint16_t lo;
uint16_t hi;
} urange16_t;
typedef struct {
uint32_t lo;
uint32_t hi;
} urange32_t;
/** substring
*
* Given two pointers to different positions in a string, allocate
* a new character array which contains the string between the two
* input pointers.
*/
char* substring(char* begin, char* end);
/** safe_strcat
*
* Like normal strcat, except this ensures that the dst array is
* large enough by checking that strlen(dst) + strlen(src) < *size,
* and reallocating if necessary, storing the new size in *size.
*/
char* safe_strcat(char* dst, char* src, int* size);
/** count_ones
*
* Count the number of ones in the binary representation of an
* integer.
*/
int count_ones(int);
/** ispow2
*
* Returns true if the given int is a power of two.
*/
bool ispow2(int);
/** strhash
*
* Hash function for a string.
*/
uint32_t strhash(char*);
#endif