aboutsummaryrefslogtreecommitdiffstats
path: root/shelpers.h
blob: 7f2ad63887b19a2e97f217e42bae09a4776f9e16 (plain)
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
#ifndef SHELPERS_H_
#define SHELPERS_H_

#include <stdint.h>

/**
 * Clones the given string, malloc'ing a new one.
 * @param s the string to clone
 * @return the malloc'd copy
 */
char *strclone(const char *s);

/**
 * Clones the given string until the given count.
 * @param s the string to clone
 * @param n the number of characters to clone
 * @return the malloc'd copy
 */
char *strnclone(const char *s, uint32_t n);


/**
 * Returns non-zero if the character is considered an end-of-line.
 * @param c a character
 * @return non-zero if eol, zero if not
 */
uint8_t eol(int c);

/**
 * Returns non-zero if the character is considered an end-of-token.
 * @param c a character
 * @return non-zero if eot, zero if not
 */
uint8_t eot(int c);

/**
 * Returns non-zero if the character is considered an end-of-expression.
 * @param c a character
 * @return non-zero if eoe, zero if not
 */
uint8_t eoe(int c);


/**
 * Finds the matching end character in a string, e.g. matching parens.
 * @param s the string to search
 * @param o the starting, opening character (e.g. '(')
 * @param c the end, closing character (e.g. ')')
 * @return offset of the end character in the string
 */
uint32_t findend(const char *s, char o, char c);

/**
 * Increments offset until the character in the string is not blank or fails
 * the given comparison.
 * @param s the string to use
 * @param cmp a comparing function, stops search if returns true
 * @param offset the variable to increment while searching
 */
void skipblank(const char *s, uint8_t (*cmp)(int), uint32_t *offset);

#endif // SHELPERS_H_