diff --git a/include/os/osString.h b/include/os/osString.h index 026cb33ad9..5f65f97bec 100644 --- a/include/os/osString.h +++ b/include/os/osString.h @@ -37,6 +37,7 @@ typedef int32_t TdUcs4; #define wcstombs WCSTOMBS_FUNC_TAOS_FORBID #define wcsncpy WCSNCPY_FUNC_TAOS_FORBID #define wchar_t WCHAR_T_TYPE_TAOS_FORBID + #define strcasestr STR_CASE_STR_FORBID #endif #ifdef WINDOWS @@ -69,6 +70,8 @@ int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size); int32_t taosWcharToMb(char *pStr, TdWchar wchar); int32_t taosWcharsToMbs(char *pStrs, TdWchar *pWchars, int32_t size); +char *taosStrCaseStr(const char *str, const char *pattern); + #ifdef __cplusplus } #endif diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 375c5001f4..7dbd301913 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -236,3 +236,22 @@ int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size) { ret int32_t taosWcharToMb(char *pStr, TdWchar wchar) { return wctomb(pStr, wchar); } int32_t taosWcharsToMbs(char *pStrs, TdWchar *pWchars, int32_t size) { return wcstombs(pStrs, pWchars, size); } + +char *taosStrCaseStr(const char *str, const char *pattern) { + size_t i; + + if (!*pattern) + return (char*)str; + + for (; *str; str++) { + if (toupper(*str) == toupper(*pattern)) { + for (i = 1;; i++) { + if (!pattern[i]) + return (char*)str; + if (toupper(str[i]) != toupper(pattern[i])) + break; + } + } + } + return NULL; +} \ No newline at end of file diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 1e832c0c46..39b97004ff 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -509,7 +509,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t bool shellIsLimitQuery(const char *sql) { //todo refactor - if (strcasestr(sql, " limit ") != NULL) { + if (taosStrCaseStr(sql, " limit ") != NULL) { return true; }