-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
44 lines (34 loc) · 812 Bytes
/
util.c
File metadata and controls
44 lines (34 loc) · 812 Bytes
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
#include <string.h>
#include <ctype.h>
#include "util.h"
char *rtrimwhitespace(char *str) {
unsigned char endloc = strlen(str) - 1;
while (isspace(str[endloc])) endloc--;
if (endloc <= 0) {
str[0] = '\0';
} else {
str[endloc + 1] = '\0';
}
return str;
}
char *ltrimwhitespace(char *str) {
unsigned char startloc = 0;
// Trim leading space
while(isspace(str[startloc])) startloc++;
if(startloc >= strlen(str)) { // All spaces?
str[0] = '\0';
} else if (startloc > 0) {
unsigned char truelen = strlen(str) - startloc;
for (int i = 0; i < truelen; i++) {
str[i] = str[i + startloc];
}
str[truelen] = '\0';
}
return str;
}
void strupper(char *str) {
int len = strlen(str);
for (int i = 0; i < len; i++) {
str[i] = toupper(str[i]);
}
}