Subversion Repositories Tewi

Rev

Rev 3 | Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 4
Line 1... Line 1...
1
/* $Id: string.c 3 2024-09-13 09:06:44Z nishi $ */
1
/* $Id: string.c 4 2024-09-13 09:39:33Z nishi $ */
2
 
2
 
3
#include <string.h>
3
#include <string.h>
4
#include <stdlib.h>
4
#include <stdlib.h>
5
 
5
 
6
char* cm_strcat(const char* a, const char* b) {
6
char* cm_strcat(const char* a, const char* b) {
Line 10... Line 10...
10
	str[strlen(a) + strlen(b)] = 0;
10
	str[strlen(a) + strlen(b)] = 0;
11
	return str;
11
	return str;
12
}
12
}
13
 
13
 
14
char* cm_strdup(const char* str) { return cm_strcat(str, ""); }
14
char* cm_strdup(const char* str) { return cm_strcat(str, ""); }
-
 
15
 
-
 
16
char* cm_trimstart(const char* str){
-
 
17
	int i;
-
 
18
	for(i = 0; str[i] != 0; i++){
-
 
19
		if(str[i] != ' ' && str[i] != '\t'){
-
 
20
			return cm_strdup(str + i);
-
 
21
		}
-
 
22
	}
-
 
23
	return cm_strdup("");
-
 
24
}
-
 
25
 
-
 
26
char* cm_trimend(const char* str){
-
 
27
	char* s = cm_strdup(str);
-
 
28
	int i;
-
 
29
	for(i = strlen(s) - 1; i >= 0; i--){
-
 
30
		if(s[i] != '\t' && s[i] != ' '){
-
 
31
			s[i + 1] = 0;
-
 
32
			break;
-
 
33
		}
-
 
34
	}
-
 
35
	return s;
-
 
36
}
-
 
37
 
-
 
38
char* cm_trim(const char* str){
-
 
39
	char* tmp = cm_trimstart(str);
-
 
40
	char* s = cm_trimend(tmp);
-
 
41
	free(tmp);
-
 
42
	return s;
-
 
43
}