fix: code merge issues
This commit is contained in:
parent
ca15163215
commit
876e7d7d8e
|
@ -96,11 +96,9 @@ int32_t taosStr2Uint32(const char *str, uint32_t *val);
|
|||
int32_t taosStr2Uint16(const char *str, uint16_t *val);
|
||||
int32_t taosStr2Uint8(const char *str, uint8_t *val);
|
||||
|
||||
int32_t taosConvInit(void);
|
||||
void taosConvDestroy();
|
||||
iconv_t taosAcquireConv(int32_t *idx, ConvType type);
|
||||
void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type);
|
||||
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
iconv_t taosAcquireConv(int32_t *idx, ConvType type, void* charsetCxt);
|
||||
void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type, void* charsetCxt);
|
||||
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, void* charsetCxt);
|
||||
int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv);
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len, void* charsetCxt);
|
||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||
|
@ -129,7 +127,6 @@ double taosStr2Double(const char *str, char **pEnd);
|
|||
float taosStr2Float(const char *str, char **pEnd);
|
||||
int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size);
|
||||
int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size);
|
||||
char *taosStrndup(const char *s, int n);
|
||||
// int32_t taosBin2Ascii(const char *z, uint32_t n, void** data, uint32_t* size);
|
||||
bool isHex(const char *z, uint32_t n);
|
||||
bool isValidateHex(const char *z, uint32_t n);
|
||||
|
|
|
@ -308,66 +308,7 @@ int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
iconv_t conv;
|
||||
int8_t inUse;
|
||||
} SConv;
|
||||
|
||||
// 0: Mbs --> Ucs4
|
||||
// 1: Ucs4--> Mbs
|
||||
SConv *gConv[2] = {NULL, NULL};
|
||||
int32_t convUsed[2] = {0, 0};
|
||||
int32_t gConvMaxNum[2] = {0, 0};
|
||||
|
||||
int32_t taosConvInit(void) {
|
||||
int8_t M2C = 0;
|
||||
gConvMaxNum[M2C] = 512;
|
||||
gConvMaxNum[1 - M2C] = 512;
|
||||
|
||||
gConv[M2C] = taosMemoryCalloc(gConvMaxNum[M2C], sizeof(SConv));
|
||||
if (gConv[M2C] == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
gConv[1 - M2C] = taosMemoryCalloc(gConvMaxNum[1 - M2C], sizeof(SConv));
|
||||
if (gConv[1 - M2C] == NULL) {
|
||||
taosMemoryFree(gConv[M2C]);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
||||
gConv[M2C][i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
if ((iconv_t)-1 == gConv[M2C][i].conv) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
||||
gConv[1 - M2C][i].conv = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
if ((iconv_t)-1 == gConv[1 - M2C][i].conv) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosConvDestroy() {
|
||||
int8_t M2C = 0;
|
||||
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
||||
(void)iconv_close(gConv[M2C][i].conv);
|
||||
}
|
||||
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
||||
(void)iconv_close(gConv[1 - M2C][i].conv);
|
||||
}
|
||||
taosMemoryFreeClear(gConv[M2C]);
|
||||
taosMemoryFreeClear(gConv[1 - M2C]);
|
||||
gConvMaxNum[M2C] = -1;
|
||||
gConvMaxNum[1 - M2C] = -1;
|
||||
}
|
||||
|
||||
iconv_t taosAcquireConv(int32_t *idx, ConvType type) {
|
||||
iconv_t taosAcquireConv(int32_t *idx, ConvType type, void* charsetCxt) {
|
||||
if(idx == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return (iconv_t)-1;
|
||||
|
@ -512,12 +453,12 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, void* chars
|
|||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(conv, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosReleaseConv(idx, conv, C2M);
|
||||
taosReleaseConv(idx, conv, C2M, charsetCxt);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
taosReleaseConv(idx, conv, C2M);
|
||||
taosReleaseConv(idx, conv, C2M, charsetCxt);
|
||||
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
#endif
|
||||
|
|
|
@ -503,6 +503,31 @@ int32_t parseCfgReal(const char *str, float *out) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool tIsValidFileName(const char *fileName, const char *pattern) {
|
||||
const char *fileNamePattern = "^[a-zA-Z0-9_.-]+$";
|
||||
|
||||
regex_t fileNameReg;
|
||||
|
||||
if (pattern) fileNamePattern = pattern;
|
||||
|
||||
if (regcomp(&fileNameReg, fileNamePattern, REG_EXTENDED) != 0) {
|
||||
fprintf(stderr, "failed to compile file name pattern:%s\n", fileNamePattern);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t code = regexec(&fileNameReg, fileName, 0, NULL, 0);
|
||||
regfree(&fileNameReg);
|
||||
if (code != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tIsValidFilePath(const char *filePath, const char *pattern) {
|
||||
const char *filePathPattern = "^[a-zA-Z0-9:/\\_.-]+$";
|
||||
return tIsValidFileName(filePath, pattern ? pattern : filePathPattern);
|
||||
}
|
||||
|
||||
bool taosIsBigChar(char c) {
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue