Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
011c8395
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看板
提交
011c8395
编写于
12月 28, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor.
上级
c801f3a7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
410 addition
and
113 deletion
+410
-113
include/util/tcompare.h
include/util/tcompare.h
+16
-13
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+10
-8
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+3
-1
source/util/src/tcompare.c
source/util/src/tcompare.c
+146
-91
source/util/test/utilTests.cpp
source/util/test/utilTests.cpp
+235
-0
未找到文件。
include/util/tcompare.h
浏览文件 @
011c8395
...
@@ -36,17 +36,18 @@ extern "C" {
...
@@ -36,17 +36,18 @@ extern "C" {
#define FLT_GREATEREQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) > (_y)))
#define FLT_GREATEREQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) > (_y)))
#define FLT_LESSEQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) < (_y)))
#define FLT_LESSEQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) < (_y)))
#define PATTERN_COMPARE_INFO_INITIALIZER \
#define PATTERN_COMPARE_INFO_INITIALIZER { '%', '_', L'%', L'_' }
{ '%', '_' }
typedef
struct
SPatternCompareInfo
{
typedef
struct
SPatternCompareInfo
{
char
matchAll
;
// symbol for match all wildcard, default: '%'
char
matchAll
;
// symbol for match all wildcard, default: '%'
char
matchOne
;
// symbol for match one wildcard, default: '_'
char
matchOne
;
// symbol for match one wildcard, default: '_'
TdUcs4
umatchAll
;
// unicode version matchAll
TdUcs4
umatchOne
;
// unicode version matchOne
}
SPatternCompareInfo
;
}
SPatternCompareInfo
;
int32_t
patternMatch
(
const
char
*
pattern
,
const
char
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
patternMatch
(
const
char
*
pattern
,
size_t
psize
,
const
char
*
str
,
size_t
s
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
WCSPatternMatch
(
const
TdUcs4
*
pattern
,
const
TdUcs4
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
wcsPatternMatch
(
const
TdUcs4
*
pattern
,
size_t
psize
,
const
TdUcs4
*
str
,
size_t
s
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
);
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
);
...
@@ -79,9 +80,11 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight);
...
@@ -79,9 +80,11 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight);
int32_t
compareLenPrefixedStr
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareLenPrefixedStr
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareLenPrefixedWStr
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareLenPrefixedWStr
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrRegexComp
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
comparestrRegexMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrRegexCompMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
comparestrRegexNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrRegexCompNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
comparewcsRegexMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
comparewcsRegexNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8ValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8ValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt16ValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt16ValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
...
@@ -99,11 +102,11 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
...
@@ -99,11 +102,11 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
int32_t
compareLenPrefixedStrDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareLenPrefixedStrDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareLenPrefixedWStrDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareLenPrefixedWStrDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
S
trPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
s
trPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
StrPatternNot
Match
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
strPatternN
Match
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
WStr
PatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
wcs
PatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
WStrPatternNot
Match
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compare
wcsPatternN
Match
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8Int16
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8Int16
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8Int32
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8Int32
(
const
void
*
pLeft
,
const
void
*
pRight
);
...
...
source/libs/scalar/src/filter.c
浏览文件 @
011c8395
...
@@ -130,9 +130,9 @@ __compar_fn_t gDataCompare[] = {compareInt32Val,
...
@@ -130,9 +130,9 @@ __compar_fn_t gDataCompare[] = {compareInt32Val,
compareFloatVal
,
compareFloatVal
,
compareDoubleVal
,
compareDoubleVal
,
compareLenPrefixedStr
,
compareLenPrefixedStr
,
compare
S
trPatternMatch
,
compare
s
trPatternMatch
,
compareChkInString
,
compareChkInString
,
compare
WStr
PatternMatch
,
compare
wcs
PatternMatch
,
compareLenPrefixedWStr
,
compareLenPrefixedWStr
,
compareUint8Val
,
compareUint8Val
,
compareUint16Val
,
compareUint16Val
,
...
@@ -142,15 +142,17 @@ __compar_fn_t gDataCompare[] = {compareInt32Val,
...
@@ -142,15 +142,17 @@ __compar_fn_t gDataCompare[] = {compareInt32Val,
setChkInBytes2
,
setChkInBytes2
,
setChkInBytes4
,
setChkInBytes4
,
setChkInBytes8
,
setChkInBytes8
,
compare
StrRegexComp
Match
,
compare
strRegex
Match
,
compare
StrRegexComp
NMatch
,
compare
strRegex
NMatch
,
setChkNotInBytes1
,
setChkNotInBytes1
,
setChkNotInBytes2
,
setChkNotInBytes2
,
setChkNotInBytes4
,
setChkNotInBytes4
,
setChkNotInBytes8
,
setChkNotInBytes8
,
compareChkNotInString
,
compareChkNotInString
,
compareStrPatternNotMatch
,
comparestrPatternNMatch
,
compareWStrPatternNotMatch
};
comparewcsPatternNMatch
,
comparewcsRegexMatch
,
comparewcsRegexNMatch
,};
__compar_fn_t
gInt8SignCompare
[]
=
{
compareInt8Val
,
compareInt8Int16
,
compareInt8Int32
,
__compar_fn_t
gInt8SignCompare
[]
=
{
compareInt8Val
,
compareInt8Int16
,
compareInt8Int32
,
compareInt8Int64
,
compareInt8Float
,
compareInt8Double
};
compareInt8Int64
,
compareInt8Float
,
compareInt8Double
};
...
@@ -295,9 +297,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
...
@@ -295,9 +297,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_NCHAR
:
{
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
optr
==
OP_TYPE_MATCH
)
{
if
(
optr
==
OP_TYPE_MATCH
)
{
comparFn
=
19
;
comparFn
=
28
;
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
comparFn
=
2
0
;
comparFn
=
2
9
;
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
comparFn
=
9
;
comparFn
=
9
;
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
011c8395
...
@@ -916,9 +916,11 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
...
@@ -916,9 +916,11 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
int32_t
vectorConvertSingleCol
(
SScalarParam
*
input
,
SScalarParam
*
output
,
int32_t
type
,
int32_t
startIndex
,
int32_t
vectorConvertSingleCol
(
SScalarParam
*
input
,
SScalarParam
*
output
,
int32_t
type
,
int32_t
startIndex
,
int32_t
numOfRows
)
{
int32_t
numOfRows
)
{
SDataType
t
=
{.
type
=
type
,
.
bytes
=
tDataTypes
[
type
].
bytes
};
output
->
numOfRows
=
input
->
numOfRows
;
output
->
numOfRows
=
input
->
numOfRows
;
SDataType
t
=
{.
type
=
type
};
t
.
bytes
=
IS_VAR_DATA_TYPE
(
t
.
type
)
?
input
->
columnData
->
info
.
bytes
:
tDataTypes
[
type
].
bytes
;
int32_t
code
=
sclCreateColumnInfoData
(
&
t
,
input
->
numOfRows
,
output
);
int32_t
code
=
sclCreateColumnInfoData
(
&
t
,
input
->
numOfRows
,
output
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
source/util/src/tcompare.c
浏览文件 @
011c8395
...
@@ -1007,59 +1007,66 @@ int32_t compareJsonValDesc(const void *pLeft, const void *pRight) { return compa
...
@@ -1007,59 +1007,66 @@ int32_t compareJsonValDesc(const void *pLeft, const void *pRight) { return compa
* '_': Matches one character
* '_': Matches one character
*
*
*/
*/
int32_t
patternMatch
(
const
char
*
patter
Str
,
const
char
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
)
{
int32_t
patternMatch
(
const
char
*
patter
n
,
size_t
psize
,
const
char
*
str
,
size_t
s
size
,
const
SPatternCompareInfo
*
pInfo
)
{
char
c
,
c1
;
char
c
,
c1
;
int32_t
i
=
0
;
int32_t
i
=
0
;
int32_t
j
=
0
;
int32_t
j
=
0
;
int32_t
o
=
0
;
int32_t
nMatchChar
=
0
;
int32_t
m
=
0
;
while
((
c
=
patter
Str
[
i
++
])
!=
0
)
{
while
((
c
=
patter
n
[
i
++
])
!=
0
&&
(
i
<=
psize
)
)
{
if
(
c
==
pInfo
->
matchAll
)
{
/* Match "*" */
if
(
c
==
pInfo
->
matchAll
)
{
/* Match "*" */
while
((
c
=
patterStr
[
i
++
])
==
pInfo
->
matchAll
||
c
==
pInfo
->
matchOne
)
{
while
((
c
=
pattern
[
i
++
])
==
pInfo
->
matchAll
||
c
==
pInfo
->
matchOne
)
{
if
(
i
>
psize
)
{
// overflow check
break
;
}
if
(
c
==
pInfo
->
matchOne
)
{
if
(
c
==
pInfo
->
matchOne
)
{
if
(
j
>
size
||
str
[
j
++
]
==
0
)
{
if
(
j
>
ssize
||
str
[
j
++
]
==
0
)
{
// empty string, return not match
// empty string, return not match
return
TSDB_PATTERN_NOWILDCARDMATCH
;
return
TSDB_PATTERN_NOWILDCARDMATCH
;
}
else
{
}
else
{
++
o
;
++
nMatchChar
;
}
}
}
}
}
}
if
(
c
==
0
)
{
if
(
c
==
0
||
i
>
psize
)
{
return
TSDB_PATTERN_MATCH
;
/* "*" at the end of the pattern matches */
return
TSDB_PATTERN_MATCH
;
/* "*" at the end of the pattern matches */
}
}
char
next
[
3
]
=
{
toupper
(
c
),
tolower
(
c
),
0
};
char
acceptArray
[
3
]
=
{
toupper
(
c
),
tolower
(
c
),
0
};
m
=
o
;
str
+=
nMatchChar
;
int32_t
remain
=
ssize
-
nMatchChar
;
while
(
1
)
{
while
(
1
)
{
size_t
n
=
strcspn
(
str
+
m
,
next
);
size_t
n
=
strcspn
(
str
,
acceptArray
);
str
+=
m
+
n
;
if
(
str
[
0
]
==
0
||
(
n
>=
size
))
{
str
+=
n
;
remain
-=
n
;
if
(
str
[
0
]
==
0
||
(
remain
<=
0
))
{
break
;
break
;
}
}
int32_t
ret
=
patternMatch
(
&
patter
Str
[
i
],
++
str
,
size
-
n
-
1
,
pInfo
);
int32_t
ret
=
patternMatch
(
&
patter
n
[
i
],
psize
-
i
,
++
str
,
--
remain
,
pInfo
);
if
(
ret
!=
TSDB_PATTERN_NOMATCH
)
{
if
(
ret
!=
TSDB_PATTERN_NOMATCH
)
{
return
ret
;
return
ret
;
}
}
m
=
0
;
}
}
return
TSDB_PATTERN_NOWILDCARDMATCH
;
return
TSDB_PATTERN_NOWILDCARDMATCH
;
}
}
c1
=
str
[
j
++
];
c1
=
str
[
j
++
];
++
o
;
++
nMatchChar
;
if
(
j
<=
size
)
{
if
(
j
<=
s
s
ize
)
{
if
(
c
==
'\\'
&&
patter
Str
[
i
]
==
'_'
&&
c1
==
'_'
)
{
if
(
c
==
'\\'
&&
patter
n
[
i
]
==
'_'
&&
c1
==
'_'
)
{
i
++
;
i
++
;
continue
;
continue
;
}
}
if
(
c
==
c1
||
tolower
(
c
)
==
tolower
(
c1
)
||
(
c
==
pInfo
->
matchOne
&&
c1
!=
0
))
{
if
(
c
==
c1
||
tolower
(
c
)
==
tolower
(
c1
)
||
(
c
==
pInfo
->
matchOne
&&
c1
!=
0
))
{
continue
;
continue
;
}
}
...
@@ -1068,39 +1075,52 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const
...
@@ -1068,39 +1075,52 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const
return
TSDB_PATTERN_NOMATCH
;
return
TSDB_PATTERN_NOMATCH
;
}
}
return
(
str
[
j
]
==
0
||
j
>=
size
)
?
TSDB_PATTERN_MATCH
:
TSDB_PATTERN_NOMATCH
;
return
(
str
[
j
]
==
0
||
j
>=
s
s
ize
)
?
TSDB_PATTERN_MATCH
:
TSDB_PATTERN_NOMATCH
;
}
}
int32_t
WCSPatternMatch
(
const
TdUcs4
*
pattern
,
const
TdUcs4
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
)
{
int32_t
wcsPatternMatch
(
const
TdUcs4
*
pattern
,
size_t
psize
,
const
TdUcs4
*
str
,
size_t
s
size
,
const
SPatternCompareInfo
*
pInfo
)
{
TdUcs4
c
,
c1
;
TdUcs4
c
,
c1
;
TdUcs4
matchOne
=
L'_'
;
// "_"
TdUcs4
matchAll
=
L'%'
;
// "%"
int32_t
i
=
0
;
int32_t
i
=
0
;
int32_t
j
=
0
;
int32_t
j
=
0
;
int32_t
nMatchChar
=
0
;
while
((
c
=
pattern
[
i
++
])
!=
0
)
{
while
((
c
=
pattern
[
i
++
])
!=
0
&&
(
i
<=
psize
))
{
if
(
c
==
matchAll
)
{
/* Match "%" */
/* Match "%" */
if
(
c
==
pInfo
->
umatchAll
)
{
while
((
c
=
pattern
[
i
++
])
==
pInfo
->
umatchAll
||
c
==
pInfo
->
umatchOne
)
{
if
(
i
>
psize
)
{
break
;
}
while
((
c
=
pattern
[
i
++
])
==
matchAll
||
c
==
matchOne
)
{
if
(
c
==
pInfo
->
u
matchOne
)
{
if
(
c
==
matchOne
&&
(
j
>=
size
||
str
[
j
++
]
==
0
)
)
{
if
(
j
>=
ssize
||
str
[
j
++
]
==
0
)
{
return
TSDB_PATTERN_NOWILDCARDMATCH
;
return
TSDB_PATTERN_NOWILDCARDMATCH
;
}
else
{
++
nMatchChar
;
}
}
}
}
}
if
(
c
==
0
)
{
if
(
c
==
0
||
i
>
psize
)
{
return
TSDB_PATTERN_MATCH
;
return
TSDB_PATTERN_MATCH
;
}
}
TdUcs4
accept
[
3
]
=
{
towupper
(
c
),
towlower
(
c
),
0
};
TdUcs4
acceptArray
[
3
]
=
{
towupper
(
c
),
towlower
(
c
),
0
};
str
+=
nMatchChar
;
int32_t
remain
=
ssize
-
nMatchChar
;
while
(
1
)
{
while
(
1
)
{
size_t
n
=
wcscspn
(
str
,
accept
);
size_t
n
=
wcscspn
(
str
,
accept
Array
);
str
+=
n
;
str
+=
n
;
if
(
str
[
0
]
==
0
||
(
n
>=
size
))
{
remain
-=
n
;
if
(
str
[
0
]
==
0
||
(
remain
<=
0
))
{
break
;
break
;
}
}
int32_t
ret
=
WCSPatternMatch
(
&
pattern
[
i
],
++
str
,
size
-
n
-
1
,
pInfo
);
int32_t
ret
=
wcsPatternMatch
(
&
pattern
[
i
],
psize
-
i
,
++
str
,
--
remain
,
pInfo
);
if
(
ret
!=
TSDB_PATTERN_NOMATCH
)
{
if
(
ret
!=
TSDB_PATTERN_NOMATCH
)
{
return
ret
;
return
ret
;
}
}
...
@@ -1110,9 +1130,15 @@ int32_t WCSPatternMatch(const TdUcs4 *pattern, const TdUcs4 *str, size_t size, c
...
@@ -1110,9 +1130,15 @@ int32_t WCSPatternMatch(const TdUcs4 *pattern, const TdUcs4 *str, size_t size, c
}
}
c1
=
str
[
j
++
];
c1
=
str
[
j
++
];
nMatchChar
++
;
if
(
j
<=
size
)
{
if
(
j
<=
ssize
)
{
if
(
c
==
c1
||
towlower
(
c
)
==
towlower
(
c1
)
||
(
c
==
matchOne
&&
c1
!=
0
))
{
if
(
c
==
L'\\'
&&
pattern
[
i
]
==
L'_'
&&
c1
==
L'_'
)
{
i
++
;
continue
;
}
if
(
c
==
c1
||
towlower
(
c
)
==
towlower
(
c1
)
||
(
c
==
pInfo
->
umatchOne
&&
c1
!=
0
))
{
continue
;
continue
;
}
}
}
}
...
@@ -1120,16 +1146,38 @@ int32_t WCSPatternMatch(const TdUcs4 *pattern, const TdUcs4 *str, size_t size, c
...
@@ -1120,16 +1146,38 @@ int32_t WCSPatternMatch(const TdUcs4 *pattern, const TdUcs4 *str, size_t size, c
return
TSDB_PATTERN_NOMATCH
;
return
TSDB_PATTERN_NOMATCH
;
}
}
return
(
str
[
j
]
==
0
||
j
>=
size
)
?
TSDB_PATTERN_MATCH
:
TSDB_PATTERN_NOMATCH
;
return
(
str
[
j
]
==
0
||
j
>=
ssize
)
?
TSDB_PATTERN_MATCH
:
TSDB_PATTERN_NOMATCH
;
}
int32_t
comparestrRegexNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
comparestrRegexMatch
(
pLeft
,
pRight
)
?
0
:
1
;
}
}
int32_t
compareStrRegexCompMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compareStrRegexComp
(
pLeft
,
pRight
);
}
static
int32_t
doExecRegexMatch
(
const
char
*
pString
,
const
char
*
pPattern
)
{
int32_t
ret
=
0
;
regex_t
regex
;
char
msgbuf
[
256
]
=
{
0
};
int32_t
cflags
=
REG_EXTENDED
;
if
((
ret
=
regcomp
(
&
regex
,
pPattern
,
cflags
))
!=
0
)
{
regerror
(
ret
,
&
regex
,
msgbuf
,
tListLen
(
msgbuf
));
uError
(
"Failed to compile regex pattern %s. reason %s"
,
pPattern
,
msgbuf
);
regfree
(
&
regex
);
return
1
;
}
ret
=
regexec
(
&
regex
,
pString
,
0
,
NULL
,
0
);
if
(
ret
!=
0
&&
ret
!=
REG_NOMATCH
)
{
regerror
(
ret
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
uDebug
(
"Failed to match %s with pattern %s, reason %s"
,
pString
,
pPattern
,
msgbuf
)
}
int32_t
compareStrRegexCompNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
regfree
(
&
regex
);
return
compareStrRegexComp
(
pLeft
,
pRight
)
?
0
:
1
;
return
(
ret
==
0
)
?
0
:
1
;
}
}
int32_t
compare
StrRegexComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
compare
strRegexMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
size_t
sz
=
varDataLen
(
pRight
);
size_t
sz
=
varDataLen
(
pRight
);
char
*
pattern
=
taosMemoryMalloc
(
sz
+
1
);
char
*
pattern
=
taosMemoryMalloc
(
sz
+
1
);
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
...
@@ -1140,30 +1188,48 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight) {
...
@@ -1140,30 +1188,48 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight) {
memcpy
(
str
,
varDataVal
(
pLeft
),
sz
);
memcpy
(
str
,
varDataVal
(
pLeft
),
sz
);
str
[
sz
]
=
0
;
str
[
sz
]
=
0
;
int32_t
errCode
=
0
;
int32_t
ret
=
doExecRegexMatch
(
str
,
pattern
);
regex_t
regex
;
char
msgbuf
[
256
]
=
{
0
};
int32_t
cflags
=
REG_EXTENDED
;
if
((
errCode
=
regcomp
(
&
regex
,
pattern
,
cflags
))
!=
0
)
{
regerror
(
errCode
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
uError
(
"Failed to compile regex pattern %s. reason %s"
,
pattern
,
msgbuf
);
regfree
(
&
regex
);
taosMemoryFree
(
str
);
taosMemoryFree
(
str
);
taosMemoryFree
(
pattern
);
taosMemoryFree
(
pattern
);
return
1
;
return
(
ret
==
0
)
?
0
:
1
;;
}
int32_t
comparewcsRegexMatch
(
const
void
*
pString
,
const
void
*
pPattern
)
{
size_t
len
=
varDataLen
(
pPattern
);
char
*
pattern
=
taosMemoryMalloc
(
len
+
1
);
int
convertLen
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
pPattern
),
len
,
pattern
);
if
(
convertLen
<
0
)
{
taosMemoryFree
(
pattern
);
return
TSDB_CODE_APP_ERROR
;
}
}
errCode
=
regexec
(
&
regex
,
str
,
0
,
NULL
,
0
);
pattern
[
len
]
=
0
;
if
(
errCode
!=
0
&&
errCode
!=
REG_NOMATCH
)
{
regerror
(
errCode
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
len
=
varDataLen
(
pString
);
uDebug
(
"Failed to match %s with pattern %s, reason %s"
,
str
,
pattern
,
msgbuf
)
char
*
str
=
taosMemoryMalloc
(
len
+
1
);
convertLen
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
pString
),
len
,
str
);
if
(
convertLen
<
0
)
{
taosMemoryFree
(
str
);
taosMemoryFree
(
pattern
);
return
TSDB_CODE_APP_ERROR
;
}
}
int32_t
result
=
(
errCode
==
0
)
?
0
:
1
;
regfree
(
&
regex
);
str
[
len
]
=
0
;
int32_t
ret
=
doExecRegexMatch
(
str
,
pattern
);
taosMemoryFree
(
str
);
taosMemoryFree
(
str
);
taosMemoryFree
(
pattern
);
taosMemoryFree
(
pattern
);
return
result
;
return
(
ret
==
0
)
?
0
:
1
;
}
int32_t
comparewcsRegexNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
comparewcsRegexMatch
(
pLeft
,
pRight
)
?
0
:
1
;
}
}
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
)
{
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
)
{
...
@@ -1173,46 +1239,35 @@ int32_t taosArrayCompareString(const void *a, const void *b) {
...
@@ -1173,46 +1239,35 @@ int32_t taosArrayCompareString(const void *a, const void *b) {
return
compareLenPrefixedStr
(
x
,
y
);
return
compareLenPrefixedStr
(
x
,
y
);
}
}
int32_t
compareStrPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
comparestrPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
SPatternCompareInfo
pInfo
=
PATTERN_COMPARE_INFO_INITIALIZER
;
assert
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
);
char
*
pattern
=
taosMemoryCalloc
(
varDataLen
(
pRight
)
+
1
,
sizeof
(
char
));
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
ASSERT
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
);
size_t
pLen
=
varDataLen
(
pRight
);
size_t
sz
=
varDataLen
(
pLeft
);
size_t
sz
=
varDataLen
(
pLeft
);
char
*
buf
=
taosMemoryMalloc
(
sz
+
1
);
memcpy
(
buf
,
varDataVal
(
pLeft
),
sz
);
buf
[
sz
]
=
0
;
int32_t
ret
=
patternMatch
(
pattern
,
buf
,
sz
,
&
pInfo
);
int32_t
ret
=
patternMatch
(
varDataVal
(
pRight
),
pLen
,
varDataVal
(
pLeft
),
sz
,
&
pInfo
);
taosMemoryFree
(
buf
);
taosMemoryFree
(
pattern
);
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
}
int32_t
compare
StrPatternNot
Match
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
compare
strPatternN
Match
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compare
S
trPatternMatch
(
pLeft
,
pRight
)
?
0
:
1
;
return
compare
s
trPatternMatch
(
pLeft
,
pRight
)
?
0
:
1
;
}
}
int32_t
compare
WStr
PatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
compare
wcs
PatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
}
;
SPatternCompareInfo
pInfo
=
PATTERN_COMPARE_INFO_INITIALIZER
;
ASSERT
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
*
TSDB_NCHAR_SIZE
);
size_t
psize
=
varDataLen
(
pRight
);
char
*
pattern
=
taosMemoryCalloc
(
varDataLen
(
pRight
)
+
TSDB_NCHAR_SIZE
,
1
);
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
int32_t
ret
=
WCSPatternMatch
((
TdUcs4
*
)
pattern
,
(
TdUcs4
*
)
varDataVal
(
pLeft
),
varDataLen
(
pLeft
)
/
TSDB_NCHAR_SIZE
,
&
pInfo
);
taosMemoryFree
(
pattern
);
int32_t
ret
=
wcsPatternMatch
((
TdUcs4
*
)
varDataVal
(
pRight
),
psize
/
TSDB_NCHAR_SIZE
,
(
TdUcs4
*
)
varDataVal
(
pLeft
),
varDataLen
(
pLeft
)
/
TSDB_NCHAR_SIZE
,
&
pInfo
);
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
}
int32_t
compare
WStrPatternNot
Match
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
compare
wcsPatternN
Match
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compare
WStr
PatternMatch
(
pLeft
,
pRight
)
?
0
:
1
;
return
compare
wcs
PatternMatch
(
pLeft
,
pRight
)
?
0
:
1
;
}
}
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
optr
)
{
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
optr
)
{
__compar_fn_t
comparFn
=
NULL
;
__compar_fn_t
comparFn
=
NULL
;
...
@@ -1285,13 +1340,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
...
@@ -1285,13 +1340,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
break
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
{
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
optr
==
OP_TYPE_MATCH
)
{
if
(
optr
==
OP_TYPE_MATCH
)
{
comparFn
=
compare
StrRegexComp
Match
;
comparFn
=
compare
strRegex
Match
;
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
comparFn
=
compare
StrRegexComp
NMatch
;
comparFn
=
compare
strRegex
NMatch
;
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
/* wildcard query using like operator */
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compare
S
trPatternMatch
;
comparFn
=
compare
s
trPatternMatch
;
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
/* wildcard query using like operator */
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compare
StrPatternNot
Match
;
comparFn
=
compare
strPatternN
Match
;
}
else
if
(
optr
==
OP_TYPE_IN
)
{
}
else
if
(
optr
==
OP_TYPE_IN
)
{
comparFn
=
compareChkInString
;
comparFn
=
compareChkInString
;
}
else
if
(
optr
==
OP_TYPE_NOT_IN
)
{
}
else
if
(
optr
==
OP_TYPE_NOT_IN
)
{
...
@@ -1305,13 +1360,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
...
@@ -1305,13 +1360,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_NCHAR
:
{
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
optr
==
OP_TYPE_MATCH
)
{
if
(
optr
==
OP_TYPE_MATCH
)
{
comparFn
=
compare
StrRegexComp
Match
;
comparFn
=
compare
wcsRegex
Match
;
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
comparFn
=
compare
StrRegexComp
NMatch
;
comparFn
=
compare
wcsRegex
NMatch
;
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
comparFn
=
compare
WStr
PatternMatch
;
comparFn
=
compare
wcs
PatternMatch
;
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
comparFn
=
compare
WStrPatternNot
Match
;
comparFn
=
compare
wcsPatternN
Match
;
}
else
if
(
optr
==
OP_TYPE_IN
)
{
}
else
if
(
optr
==
OP_TYPE_IN
)
{
comparFn
=
compareChkInString
;
comparFn
=
compareChkInString
;
}
else
if
(
optr
==
OP_TYPE_NOT_IN
)
{
}
else
if
(
optr
==
OP_TYPE_NOT_IN
)
{
...
...
source/util/test/utilTests.cpp
浏览文件 @
011c8395
#include <gtest/gtest.h>
#include <stdlib.h>
#include <random>
#include "tarray.h"
#include "tcompare.h"
namespace
{
}
// namespace
TEST
(
utilTest
,
wchar_pattern_match_test
)
{
const
TdWchar
*
pattern
=
L"%1"
;
int32_t
ret
=
0
;
SPatternCompareInfo
pInfo
=
PATTERN_COMPARE_INFO_INITIALIZER
;
const
TdWchar
*
str0
=
L"14"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str0
),
wcslen
(
str0
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
str1
=
L"11"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str1
),
wcslen
(
str1
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
str2
=
L"41"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str2
),
wcslen
(
str2
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern3
=
L"%_"
;
const
TdWchar
*
str3
=
L"88"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern3
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str3
),
wcslen
(
str3
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern4
=
L"%___"
;
const
TdWchar
*
str4
=
L"88"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern4
),
4
,
reinterpret_cast
<
const
TdUcs4
*>
(
str4
),
wcslen
(
str4
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
pattern5
=
L"%___"
;
const
TdWchar
*
str5
=
L"883391"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern5
),
4
,
reinterpret_cast
<
const
TdUcs4
*>
(
str5
),
wcslen
(
str5
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern6
=
L"%___66"
;
const
TdWchar
*
str6
=
L"88339166"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern6
),
6
,
reinterpret_cast
<
const
TdUcs4
*>
(
str6
),
wcslen
(
str6
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern7
=
L"%____66"
;
const
TdWchar
*
str7
=
L"66166"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern7
),
7
,
reinterpret_cast
<
const
TdUcs4
*>
(
str7
),
wcslen
(
str7
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
pattern8
=
L"6%____66"
;
const
TdWchar
*
str8
=
L"666166"
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern8
),
8
,
reinterpret_cast
<
const
TdUcs4
*>
(
str8
),
wcslen
(
str8
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
pattern9
=
L"6
\\
__6"
;
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
);
}
TEST
(
utilTest
,
wchar_pattern_match_no_terminated
)
{
const
TdWchar
*
pattern
=
L"%1 "
;
int32_t
ret
=
0
;
SPatternCompareInfo
pInfo
=
PATTERN_COMPARE_INFO_INITIALIZER
;
const
TdWchar
*
str0
=
L"14 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str0
),
2
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
str1
=
L"11 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str1
),
2
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
str2
=
L"41 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str2
),
2
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern3
=
L"%_ "
;
const
TdWchar
*
str3
=
L"88 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern3
),
2
,
reinterpret_cast
<
const
TdUcs4
*>
(
str3
),
2
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern4
=
L"%___ "
;
const
TdWchar
*
str4
=
L"88 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern4
),
4
,
reinterpret_cast
<
const
TdUcs4
*>
(
str4
),
2
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
pattern5
=
L"%___ "
;
const
TdWchar
*
str5
=
L"883391 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern5
),
4
,
reinterpret_cast
<
const
TdUcs4
*>
(
str5
),
6
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern6
=
L"%___66 "
;
const
TdWchar
*
str6
=
L"88339166 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern6
),
6
,
reinterpret_cast
<
const
TdUcs4
*>
(
str6
),
8
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern7
=
L"%____66 "
;
const
TdWchar
*
str7
=
L"66166 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern7
),
7
,
reinterpret_cast
<
const
TdUcs4
*>
(
str7
),
5
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
pattern8
=
L"6%____66 "
;
const
TdWchar
*
str8
=
L"666166 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern8
),
8
,
reinterpret_cast
<
const
TdUcs4
*>
(
str8
),
6
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
TdWchar
*
pattern9
=
L"6
\\
_6 "
;
const
TdWchar
*
str9
=
L"6_6 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern9
),
4
,
reinterpret_cast
<
const
TdUcs4
*>
(
str9
),
3
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
TdWchar
*
pattern10
=
L"% "
;
const
TdWchar
*
str10
=
L"6_6 "
;
ret
=
wcsPatternMatch
(
reinterpret_cast
<
const
TdUcs4
*>
(
pattern10
),
1
,
reinterpret_cast
<
const
TdUcs4
*>
(
str10
),
3
,
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
}
TEST
(
utilTest
,
char_pattern_match_test
)
{
const
char
*
pattern
=
"%1"
;
int32_t
ret
=
0
;
SPatternCompareInfo
pInfo
=
PATTERN_COMPARE_INFO_INITIALIZER
;
const
char
*
str0
=
"14"
;
ret
=
patternMatch
(
pattern
,
2
,
str0
,
strlen
(
str0
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
str1
=
"11"
;
ret
=
patternMatch
(
pattern
,
2
,
str1
,
strlen
(
str1
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
str2
=
"41"
;
ret
=
patternMatch
(
pattern
,
2
,
str2
,
strlen
(
str2
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern3
=
"%_"
;
const
char
*
str3
=
"88"
;
ret
=
patternMatch
(
pattern3
,
2
,
str3
,
strlen
(
str3
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern4
=
"%___"
;
const
char
*
str4
=
"88"
;
ret
=
patternMatch
(
pattern4
,
4
,
str4
,
strlen
(
str4
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
pattern5
=
"%___"
;
const
char
*
str5
=
"883391"
;
ret
=
patternMatch
(
pattern5
,
4
,
str5
,
strlen
(
str5
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern6
=
"%___66"
;
const
char
*
str6
=
"88339166"
;
ret
=
patternMatch
(
pattern6
,
6
,
str6
,
strlen
(
str6
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern7
=
"%____66"
;
const
char
*
str7
=
"66166"
;
ret
=
patternMatch
(
pattern7
,
7
,
str7
,
strlen
(
str7
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
pattern8
=
"6%____66"
;
const
char
*
str8
=
"666166"
;
ret
=
patternMatch
(
pattern8
,
8
,
str8
,
strlen
(
str8
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
pattern9
=
"6
\\
_6"
;
const
char
*
str9
=
"6_6"
;
ret
=
patternMatch
(
pattern9
,
5
,
str9
,
strlen
(
str9
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
}
TEST
(
utilTest
,
char_pattern_match_no_terminated
)
{
const
char
*
pattern
=
"%1 "
;
int32_t
ret
=
0
;
SPatternCompareInfo
pInfo
=
PATTERN_COMPARE_INFO_INITIALIZER
;
const
char
*
str0
=
"14"
;
ret
=
patternMatch
(
pattern
,
2
,
str0
,
strlen
(
str0
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
str1
=
"11"
;
ret
=
patternMatch
(
pattern
,
2
,
str1
,
strlen
(
str1
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
str2
=
"41"
;
ret
=
patternMatch
(
pattern
,
2
,
str2
,
strlen
(
str2
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern3
=
"%_ "
;
const
char
*
str3
=
"88"
;
ret
=
patternMatch
(
pattern3
,
2
,
str3
,
strlen
(
str3
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern4
=
"%___ "
;
const
char
*
str4
=
"88"
;
ret
=
patternMatch
(
pattern4
,
4
,
str4
,
strlen
(
str4
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
pattern5
=
"%___ "
;
const
char
*
str5
=
"883391"
;
ret
=
patternMatch
(
pattern5
,
4
,
str5
,
strlen
(
str5
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern6
=
"%___66 "
;
const
char
*
str6
=
"88339166"
;
ret
=
patternMatch
(
pattern6
,
6
,
str6
,
strlen
(
str6
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern7
=
"%____66 "
;
const
char
*
str7
=
"66166"
;
ret
=
patternMatch
(
pattern7
,
7
,
str7
,
strlen
(
str7
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
pattern8
=
"6%____66 "
;
const
char
*
str8
=
"666166"
;
ret
=
patternMatch
(
pattern8
,
8
,
str8
,
strlen
(
str8
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
const
char
*
pattern9
=
"6
\\
_6 "
;
const
char
*
str9
=
"6_6"
;
ret
=
patternMatch
(
pattern9
,
4
,
str9
,
strlen
(
str9
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
const
char
*
pattern10
=
"% "
;
const
char
*
str10
=
"6_6"
;
ret
=
patternMatch
(
pattern10
,
1
,
str10
,
strlen
(
str10
),
&
pInfo
);
ASSERT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录