osString.h 2.8 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
Shengliang Guan 已提交
16 17
#ifndef _TD_OS_STRING_H_
#define _TD_OS_STRING_H_
S
Shengliang Guan 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

wafwerar's avatar
wafwerar 已提交
23 24 25
typedef wchar_t TdWchar;
typedef int32_t TdUcs4;

wafwerar's avatar
wafwerar 已提交
26
// If the error is in a third-party library, place this header file under the third-party library header file.
wafwerar's avatar
wafwerar 已提交
27
// When you want to use this feature, you should find or add the same function in the following section.
wafwerar's avatar
wafwerar 已提交
28 29 30 31
#ifndef ALLOW_FORBID_FUNC
    #define iconv_open ICONV_OPEN_FUNC_TAOS_FORBID
    #define iconv_close ICONV_CLOSE_FUNC_TAOS_FORBID
    #define iconv ICONV_FUNC_TAOS_FORBID
wafwerar's avatar
wafwerar 已提交
32 33 34 35 36 37 38
    #define wcwidth WCWIDTH_FUNC_TAOS_FORBID
    #define wcswidth WCSWIDTH_FUNC_TAOS_FORBID
    #define mbtowc MBTOWC_FUNC_TAOS_FORBID
    #define mbstowcs MBSTOWCS_FUNC_TAOS_FORBID
    #define wctomb WCTOMB_FUNC_TAOS_FORBID
    #define wcstombs WCSTOMBS_FUNC_TAOS_FORBID
    #define wcsncpy WCSNCPY_FUNC_TAOS_FORBID
wafwerar's avatar
wafwerar 已提交
39
    #define wchar_t WCHAR_T_TYPE_TAOS_FORBID
wafwerar's avatar
wafwerar 已提交
40
    #define strcasestr STR_CASE_STR_FORBID
wafwerar's avatar
wafwerar 已提交
41 42
#endif

wafwerar's avatar
wafwerar 已提交
43
#ifdef WINDOWS
S
TD-4088  
Shengliang Guan 已提交
44 45 46 47
  #define tstrdup(str) _strdup(str)
#else
  #define tstrdup(str) strdup(str)
#endif
S
Shengliang Guan 已提交
48

S
TD-4088  
Shengliang Guan 已提交
49 50 51 52
#define tstrncpy(dst, src, size) \
  do {                              \
    strncpy((dst), (src), (size));  \
    (dst)[(size)-1] = 0;            \
53
  } while (0)
S
Shengliang Guan 已提交
54

wafwerar's avatar
wafwerar 已提交
55
int32_t taosUcs4len(TdUcs4 *ucs4);
56
int64_t taosStr2int64(const char *str);
S
Shengliang Guan 已提交
57

wafwerar's avatar
wafwerar 已提交
58 59 60
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs);
bool    taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len);
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
wafwerar's avatar
wafwerar 已提交
61
TdUcs4* tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
S
Shengliang Guan 已提交
62
bool    taosValidateEncodec(const char *encodec);
63 64
int32_t taosHexEncode(const char *src, char *dst, int32_t len);
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
S
Shengliang Guan 已提交
65

wafwerar's avatar
wafwerar 已提交
66 67 68 69 70 71 72
int32_t taosWcharWidth(TdWchar wchar);
int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size);
int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size);
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);

wafwerar's avatar
wafwerar 已提交
73 74
char *taosStrCaseStr(const char *str, const char *pattern);

S
Shengliang Guan 已提交
75 76 77 78
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
79
#endif /*_TD_OS_STRING_H_*/