Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2a8f8776
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2a8f8776
编写于
12月 17, 2021
作者:
D
dapan1121
提交者:
GitHub
12月 17, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9122 from taosdata/fix/TD-11201
Fix/td 11201
上级
f81d65ba
4585cf61
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
25 deletion
+59
-25
src/util/src/tutil.c
src/util/src/tutil.c
+21
-25
src/util/tests/stringTest.cpp
src/util/tests/stringTest.cpp
+38
-0
未找到文件。
src/util/src/tutil.c
浏览文件 @
2a8f8776
...
...
@@ -57,36 +57,32 @@ int32_t strdequote(char *z) {
return
j
+
1
;
// only one quote, do nothing
}
// delete escape character: \\, \', \"
int32_t
strRmquote
(
char
*
z
,
int32_t
len
){
// delete escape character: \\, \', \"
char
delim
=
z
[
0
];
if
(
delim
!=
'\''
&&
delim
!=
'\"'
)
{
return
len
;
char
delim
=
0
;
int32_t
cnt
=
0
;
int32_t
j
=
0
;
for
(
size_t
k
=
0
;
k
<
len
;
++
k
)
{
if
(
!
delim
&&
(
z
[
k
]
==
'\''
||
z
[
k
]
==
'"'
)){
// find the start ' or "
delim
=
z
[
k
];
}
int32_t
cnt
=
0
;
int32_t
j
=
0
;
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
if
(
z
[
k
]
==
'\\'
||
(
z
[
k
]
==
delim
&&
z
[
k
+
1
]
==
delim
))
{
if
((
z
[
k
]
==
'\\'
&&
z
[
k
+
1
]
==
'_'
)
||
(
z
[
k
]
==
'\\'
&&
z
[
k
+
1
]
==
'%'
))
{
//match '_' self
}
else
{
z
[
j
]
=
z
[
k
+
1
];
cnt
++
;
j
++
;
k
++
;
continue
;
}
}
z
[
j
]
=
z
[
k
];
if
((
z
[
k
]
==
'\\'
&&
z
[
k
+
1
]
==
'_'
)
||
(
z
[
k
]
==
'\\'
&&
z
[
k
+
1
]
==
'%'
))
{
//match '_' '%' self
}
else
if
(
z
[
k
]
==
'\\'
){
z
[
j
]
=
z
[
k
+
1
];
cnt
++
;
j
++
;
k
++
;
continue
;
}
else
if
(
z
[
k
]
==
delim
){
continue
;
}
z
[
j
]
=
0
;
return
len
-
2
-
cnt
;
z
[
j
]
=
z
[
k
];
j
++
;
}
z
[
j
]
=
0
;
return
j
;
}
int32_t
strRmquoteEscape
(
char
*
z
,
int32_t
len
)
{
...
...
src/util/tests/stringTest.cpp
浏览文件 @
2a8f8776
...
...
@@ -6,6 +6,44 @@
#include "taos.h"
#include "tutil.h"
TEST
(
testCase
,
str_rmquote_test
)
{
char
t1
[]
=
"
\"\"
.dd"
;
int32_t
len
=
strRmquote
(
t1
,
strlen
(
t1
));
printf
(
"t1:%s, len:%d
\n
"
,
t1
,
len
);
EXPECT_EQ
(
3
,
len
);
EXPECT_STRCASEEQ
(
t1
,
".dd"
);
char
t2
[]
=
"
\"
fsd
\\\"
fs
\"
.dd"
;
len
=
strRmquote
(
t2
,
strlen
(
t2
));
printf
(
"t2:%s, len:%d
\n
"
,
t2
,
len
);
EXPECT_EQ
(
9
,
len
);
EXPECT_STRCASEEQ
(
t2
,
"fsd
\"
fs.dd"
);
char
t3
[]
=
"fs
\\
_d
\\
%.d
\\
d"
;
len
=
strRmquote
(
t3
,
strlen
(
t3
));
printf
(
"t3:%s, len:%d
\n
"
,
t3
,
len
);
EXPECT_EQ
(
10
,
len
);
EXPECT_STRCASEEQ
(
t3
,
"fs
\\
_d
\\
%.dd"
);
char
t4
[]
=
"
\"
fs
\\
_d
\\
%
\"
.dd"
;
len
=
strRmquote
(
t4
,
strlen
(
t4
));
printf
(
"t4:%s, len:%d
\n
"
,
t4
,
len
);
EXPECT_EQ
(
10
,
len
);
EXPECT_STRCASEEQ
(
t4
,
"fs
\\
_d
\\
%.dd"
);
char
t5
[]
=
"
\"
fs
\\
_d
\\
%
\"
"
;
len
=
strRmquote
(
t5
,
strlen
(
t5
));
printf
(
"t5:%s, len:%d
\n
"
,
t5
,
len
);
EXPECT_EQ
(
7
,
len
);
EXPECT_STRCASEEQ
(
t5
,
"fs
\\
_d
\\
%"
);
char
t6
[]
=
"'fs
\\
_d
\\
%'"
;
len
=
strRmquote
(
t6
,
strlen
(
t6
));
printf
(
"t6:%s, len:%d
\n
"
,
t6
,
len
);
EXPECT_EQ
(
7
,
len
);
EXPECT_STRCASEEQ
(
t6
,
"fs
\\
_d
\\
%"
);
}
TEST
(
testCase
,
string_dequote_test
)
{
char
t1
[]
=
"'abc'"
;
int32_t
len
=
strdequote
(
t1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录