Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f970dd24
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看板
提交
f970dd24
编写于
12月 29, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): fix the invalid access.
上级
0e471afc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
67 addition
and
8 deletion
+67
-8
include/util/tutil.h
include/util/tutil.h
+4
-0
source/util/src/tcompare.c
source/util/src/tcompare.c
+9
-8
source/util/src/tutil.c
source/util/src/tutil.c
+24
-0
source/util/test/utilTests.cpp
source/util/test/utilTests.cpp
+30
-0
未找到文件。
include/util/tutil.h
浏览文件 @
f970dd24
...
...
@@ -29,12 +29,16 @@ extern "C" {
int32_t
strdequote
(
char
*
src
);
size_t
strtrim
(
char
*
src
);
char
*
strnchr
(
const
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
);
TdUcs4
*
wcsnchr
(
const
TdUcs4
*
haystack
,
TdUcs4
needle
,
size_t
len
);
char
**
strsplit
(
char
*
src
,
const
char
*
delim
,
int32_t
*
num
);
char
*
strtolower
(
char
*
dst
,
const
char
*
src
);
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
);
char
*
strntolower_s
(
char
*
dst
,
const
char
*
src
,
int32_t
n
);
int64_t
strnatoi
(
char
*
num
,
int32_t
len
);
size_t
tstrncspn
(
const
char
*
str
,
size_t
ssize
,
const
char
*
reject
,
size_t
rsize
);
size_t
twcsncspn
(
const
TdUcs4
*
wcs
,
size_t
size
,
const
TdUcs4
*
reject
,
size_t
rsize
);
char
*
strbetween
(
char
*
string
,
char
*
begin
,
char
*
end
);
char
*
paGetToken
(
char
*
src
,
char
**
token
,
int32_t
*
tokenLen
);
...
...
source/util/src/tcompare.c
浏览文件 @
f970dd24
...
...
@@ -998,6 +998,7 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
}
int32_t
compareJsonValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compareJsonVal
(
pRight
,
pLeft
);
}
/*
* Compare two strings
* TSDB_MATCH: Match
...
...
@@ -1055,10 +1056,10 @@ int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t
return
TSDB_PATTERN_NOWILDCARDMATCH
;
}
c1
=
str
[
j
++
];
++
nMatchChar
;
if
(
j
<
ssize
)
{
c1
=
str
[
j
++
];
++
nMatchChar
;
if
(
j
<=
ssize
)
{
if
(
c
==
'\\'
&&
pattern
[
i
]
==
'_'
&&
c1
==
'_'
)
{
i
++
;
continue
;
...
...
@@ -1099,12 +1100,12 @@ int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str,
return
TSDB_PATTERN_MATCH
;
}
TdUcs4
acceptArray
[
3
]
=
{
towupper
(
c
),
towlower
(
c
),
0
};
TdUcs4
rejectList
[
2
]
=
{
towupper
(
c
),
towlower
(
c
)
};
str
+=
nMatchChar
;
int32_t
remain
=
ssize
-
nMatchChar
;
while
(
1
)
{
size_t
n
=
wcscspn
(
str
,
acceptArray
);
size_t
n
=
twcsncspn
(
str
,
remain
,
rejectList
,
2
);
str
+=
n
;
remain
-=
n
;
...
...
@@ -1122,10 +1123,10 @@ int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str,
return
TSDB_PATTERN_NOWILDCARDMATCH
;
}
c1
=
str
[
j
++
];
nMatchChar
++
;
if
(
j
<
ssize
)
{
c1
=
str
[
j
++
];
nMatchChar
++
;
if
(
j
<=
ssize
)
{
if
(
c
==
L'\\'
&&
pattern
[
i
]
==
L'_'
&&
c1
==
L'_'
)
{
i
++
;
continue
;
...
...
source/util/src/tutil.c
浏览文件 @
f970dd24
...
...
@@ -144,6 +144,16 @@ char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote) {
return
NULL
;
}
TdUcs4
*
wcsnchr
(
const
TdUcs4
*
haystack
,
TdUcs4
needle
,
size_t
len
)
{
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
haystack
[
i
]
==
needle
)
{
return
(
TdUcs4
*
)
&
haystack
[
i
];
}
}
return
NULL
;
}
char
*
strtolower
(
char
*
dst
,
const
char
*
src
)
{
int32_t
esc
=
0
;
char
quote
=
0
,
*
p
=
dst
,
c
;
...
...
@@ -432,3 +442,17 @@ size_t tstrncspn(const char *str, size_t size, const char *reject, size_t rsize)
return
size
;
}
size_t
twcsncspn
(
const
TdUcs4
*
wcs
,
size_t
size
,
const
TdUcs4
*
reject
,
size_t
rsize
)
{
if
(
rsize
==
0
||
rsize
==
1
)
{
TdUcs4
*
p
=
wcsnchr
(
wcs
,
reject
[
0
],
size
);
return
(
p
==
NULL
)
?
size
:
(
p
-
wcs
);
}
size_t
index
=
0
;
while
((
index
<
size
)
&&
(
wcsnchr
(
reject
,
wcs
[
index
],
rsize
)
==
NULL
))
{
++
index
;
}
return
index
;
}
source/util/test/utilTests.cpp
浏览文件 @
f970dd24
...
...
@@ -61,6 +61,21 @@ TEST(utilTest, wchar_pattern_match_test) {
const
TdWchar
*
str9
=
L"6_66"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern9
),
6
,
reinterpret_cast
<
const
TdUcs4
*>
(
str9
),
wcslen
(
str9
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern10
=
L"%"
;
const
TdWchar
*
str10
=
L""
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern10
),
1
,
reinterpret_cast
<
const
TdUcs4
*>
(
str10
),
0
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern11
=
L"china%"
;
const
TdWchar
*
str11
=
L"CHI "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern11
),
6
,
reinterpret_cast
<
const
TdUcs4
*>
(
str11
),
3
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOMATCH
);
const
TdWchar
*
pattern12
=
L"abc%"
;
const
TdWchar
*
str12
=
L""
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern12
),
4
,
reinterpret_cast
<
const
TdUcs4
*>
(
str12
),
0
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOMATCH
);
}
TEST
(
utilTest
,
wchar_pattern_match_no_terminated
)
{
...
...
@@ -174,6 +189,21 @@ TEST(utilTest, char_pattern_match_test) {
const
char
*
str9
=
"6_6"
;
ret
=
patternMatch
(
pattern9
,
5
,
str9
,
strlen
(
str9
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern10
=
"%"
;
const
char
*
str10
=
" "
;
ret
=
patternMatch
(
pattern10
,
1
,
str10
,
0
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern11
=
"china%"
;
const
char
*
str11
=
"abc "
;
ret
=
patternMatch
(
pattern11
,
6
,
str11
,
3
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOMATCH
);
const
char
*
pattern12
=
"abc%"
;
const
char
*
str12
=
NULL
;
ret
=
patternMatch
(
pattern12
,
4
,
str12
,
0
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOMATCH
);
}
TEST
(
utilTest
,
char_pattern_match_no_terminated
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录