Changeset 5 in Main for trunk/Common/string.c
- Timestamp:
- Sep 13, 2024, 7:08:00 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/string.c
r4 r5 3 3 #include <string.h> 4 4 #include <stdlib.h> 5 #include <stdbool.h> 6 #include <ctype.h> 5 7 6 8 char* cm_strcat(const char* a, const char* b) { … … 42 44 return s; 43 45 } 46 47 char** cm_split(const char* str, const char* by){ 48 int i; 49 char** r = malloc(sizeof(*r)); 50 r[0] = NULL; 51 char* b = malloc(1); 52 b[0] = 0; 53 char cbuf[2]; 54 cbuf[1] = 0; 55 bool dq = false; 56 bool sq = false; 57 for(i = 0;; i++){ 58 int j; 59 bool has = false; 60 for(j = 0; by[j] != 0; j++){ 61 if(by[j] == str[i]){ 62 has = true; 63 break; 64 } 65 } 66 if(!(dq || sq) && (has || str[i] == 0)){ 67 if(strlen(b) > 0){ 68 char** old = r; 69 int j; 70 for(j = 0; old[j] != NULL; j++); 71 r = malloc(sizeof(*r) * (j + 2)); 72 for(j = 0; old[j] != NULL; j++) r[j] = old[j]; 73 r[j] = b; 74 r[j + 1] = NULL; 75 free(old); 76 } 77 b = malloc(1); 78 b[0] = 0; 79 if(str[i] == 0) break; 80 }else{ 81 if(str[i] == '"' && !sq){ 82 dq = !dq; 83 }else if(str[i] == '\'' && !dq){ 84 sq = !sq; 85 }else{ 86 cbuf[0] = str[i]; 87 char* tmp = b; 88 b = cm_strcat(tmp, cbuf); 89 free(tmp); 90 } 91 } 92 } 93 free(b); 94 return r; 95 } 96 97 bool cm_strcaseequ(const char* a, const char* b){ 98 if(a == NULL) return false; 99 if(b == NULL) return false; 100 if(strlen(a) != strlen(b)) return false; 101 int i; 102 for(i = 0; a[i] != 0; i++){ 103 if(tolower(a[i]) != tolower(b[i])) return false; 104 } 105 return true; 106 }
Note:
See TracChangeset
for help on using the changeset viewer.