提交 a10c0e97 编写于 作者: weixin_48148422's avatar weixin_48148422

fix strtolower

上级 90e5690d
...@@ -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;
}
while (*str) { assert(dst != NULL);
if (*str == '\'' || *str == '"') {
quote = quote ^ 1;
}
if ((!quote) && (*str >= 'A' && *str <= 'Z')) { for (c = *src++; c; c = *src++) {
*dst++ = *str | 0x20; if (esc) {
} else { esc = 0;
*dst++ = *str; } else if (quote) {
if (c == '\\') {
esc = 1;
} else if (c == quote) {
quote = 0;
} }
} else if (c >= 'A' && c <= 'Z') {
str++; c -= 'A' - 'a';
} else if (c == '\'' || c == '"') {
quote = c;
}
*p++ = c;
} }
*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.
先完成此消息的编辑!
想要评论请 注册