This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
string-helpers.h
70 lines (60 loc) · 2.35 KB
/
string-helpers.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
#ifndef STRING_HELPERS_H
#define STRING_HELPERS_H
/*
Given a single character 'c', this function returns 1 if the character is
an English alphabet character (upper or lowercae). Otherwise, the
function returns 0.
*/
int is_alpha(char c);
/*
Given a single character 'c', the function returns 1 if the character is a
(white)space character according to our grammar. If it is not a
(white)space character, the function returns 0.
*/
int is_space(char c);
/*
Given a single character 'c', the function returns 1 if the charcter is a
digit according to our grammar. If it is not, the function returns 0.
*/
int is_digit(char c);
/*
Given a character pointer 'str', this function first checks to see if
the first character is an escaped character. If it is not, it returns -1.
If it is an escaped character, it returns the character which is escaped.
*/
int replace_escape_in_character(char* str);
/*
Given a character pointer 'str', this function first checks to see if
the first character is an escaped character. If it is not, it returns -1.
If it is an escaped character, it returns the character which is escaped.
Note: The escape characters valid in strings and characters differ, hence
the two separate functions. Please see the lexing grammar for details.
*/
int replace_escape_in_string(char* str);
/*
Given a single character 'c', this function returns 1 if the character is
a component of an identifier (letter, digit, or underscore). Otherwise,
the function returns 0.
*/
int is_identifier_component(char c);
/*
Given a character pointer 'str', this function returns 1 if the string
is a valid identifier. Consider using the function above! If it is not
a valid identifier, the function returns 0.
*/
int is_valid_identifier(char* str);
/*
Given two character pointers 'src' and 'dest', this function copies from
'src' to 'dest' and changes every uppercase character to
lowercase.
The resulting string in 'dest' is null terminated.
*/
void lower_strcpy(char* dest, char* src);
/*
Given a list of character pointers 'strings' and the length of the list
'count', this function returns a newly allocated character pointer
containing all characters in 'strings' concatenated together.
The returned character pointer should be null terminated.
*/
char* str_concat(char** strings, size_t count);
#endif