Changeset 212 in Main for trunk/Common/string.c
- Timestamp:
- Oct 3, 2024, 2:44:55 AM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/string.c
r70 r212 8 8 9 9 char* cm_strcat(const char* a, const char* b) { 10 char* str; 10 11 if(a == NULL) a = ""; 11 12 if(b == NULL) b = ""; 12 char*str = malloc(strlen(a) + strlen(b) + 1);13 str = malloc(strlen(a) + strlen(b) + 1); 13 14 memcpy(str, a, strlen(a)); 14 15 memcpy(str + strlen(a), b, strlen(b)); … … 27 28 28 29 bool cm_endswith(const char* str, const char* end) { 30 int i; 29 31 if(strlen(str) < strlen(end)) return false; 30 int i;31 32 for(i = strlen(str) - strlen(end); i < strlen(str); i++) { 32 33 if(str[i] != end[i - strlen(str) + strlen(end)]) return false; … … 36 37 37 38 bool cm_nocase_endswith(const char* str, const char* end) { 39 int i; 38 40 if(strlen(str) < strlen(end)) return false; 39 int i;40 41 for(i = strlen(str) - strlen(end); i < strlen(str); i++) { 41 42 if(tolower(str[i]) != tolower(end[i - strlen(str) + strlen(end)])) return false; … … 76 77 int i; 77 78 char** r = malloc(sizeof(*r)); 78 r[0] = NULL;79 79 char* b = malloc(1); 80 b[0] = 0;81 80 char cbuf[2]; 82 cbuf[1] = 0;83 81 bool dq = false; 84 82 bool sq = false; 83 r[0] = NULL; 84 b[0] = 0; 85 cbuf[1] = 0; 85 86 for(i = 0;; i++) { 86 87 int j; … … 113 114 sq = !sq; 114 115 } else { 116 char* tmp = b; 115 117 cbuf[0] = str[i]; 116 char* tmp = b;117 118 b = cm_strcat(tmp, cbuf); 118 119 free(tmp); … … 125 126 126 127 bool cm_strcaseequ(const char* a, const char* b) { 128 int i; 127 129 if(a == NULL) return false; 128 130 if(b == NULL) return false; 129 131 if(strlen(a) != strlen(b)) return false; 130 int i;131 132 for(i = 0; a[i] != 0; i++) { 132 133 if(tolower(a[i]) != tolower(b[i])) return false; … … 155 156 int i; 156 157 char* result = malloc(1); 158 char cbuf[2]; 157 159 result[0] = 0; 158 char cbuf[2];159 160 cbuf[1] = 0; 160 161 for(i = 0; str[i] != 0; i++) { … … 184 185 int i; 185 186 char* result = malloc(1); 187 char cbuf[2]; 186 188 result[0] = 0; 187 char cbuf[2];188 189 cbuf[1] = 0; 189 190 for(i = 0; str[i] != 0; i++) { … … 191 192 if('!' <= str[i] && str[i] <= '@' && str[i] != '.' && str[i] != '-' && str[i] != '/' && !('0' <= str[i] && str[i] <= '9')) { 192 193 char code[4]; 194 char* tmp = result; 193 195 sprintf(code, "%%%02X", str[i]); 194 char* tmp = result;195 196 result = cm_strcat(tmp, code); 196 197 free(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.