未验证 提交 18d26406 编写于 作者: H haojun Liao 提交者: GitHub

Merge pull request #415 from localvar/fix-strtolower

fix strtolower
...@@ -184,7 +184,7 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote); ...@@ -184,7 +184,7 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote);
char **strsplit(char *src, const char *delim, int32_t *num); char **strsplit(char *src, const char *delim, int32_t *num);
void strtolower(char *dst, const char *src); char* strtolower(char *dst, const char *src);
int64_t strnatoi(char *num, int32_t len); int64_t strnatoi(char *num, int32_t len);
......
...@@ -140,28 +140,31 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) { ...@@ -140,28 +140,31 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
return NULL; return NULL;
} }
void strtolower(char *dst, const char *z) { char* strtolower(char *dst, const char *src) {
int quote = 0; int esc = 0;
char *str = z; char quote = 0, *p = dst, c;
if (dst == NULL) {
return; assert(dst != NULL);
}
for (c = *src++; c; c = *src++) {
while (*str) { if (esc) {
if (*str == '\'' || *str == '"') { esc = 0;
quote = quote ^ 1; } else if (quote) {
} if (c == '\\') {
esc = 1;
if ((!quote) && (*str >= 'A' && *str <= 'Z')) { } else if (c == quote) {
*dst++ = *str | 0x20; quote = 0;
} else { }
*dst++ = *str; } else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 'a';
} else if (c == '\'' || c == '"') {
quote = c;
} }
*p++ = c;
str++;
} }
*dst = 0; *p = 0;
return dst;
} }
char *paGetToken(char *string, char **token, int32_t *tokenLen) { char *paGetToken(char *string, char **token, int32_t *tokenLen) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册