Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
e33049d2
Commit
e33049d2
authored
May 07, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix minLength & maxLength with code point instead of code unit
parent
9c0e409f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
encodings.h
include/rapidjson/encodings.h
+16
-0
schema.h
include/rapidjson/schema.h
+7
-2
encodingstest.cpp
test/unittest/encodingstest.cpp
+11
-0
No files found.
include/rapidjson/encodings.h
View file @
e33049d2
...
...
@@ -616,6 +616,22 @@ struct Transcoder<Encoding, Encoding> {
}
};
//! Returns number of code points in a encoded string.
template
<
typename
Encoding
>
bool
CountStringCodePoint
(
const
typename
Encoding
::
Ch
*
s
,
SizeType
length
,
SizeType
*
outCount
)
{
GenericStringStream
<
Encoding
>
is
(
s
);
const
typename
Encoding
::
Ch
*
end
=
s
+
length
;
SizeType
count
=
0
;
while
(
is
.
src_
<
end
)
{
unsigned
codepoint
;
if
(
!
Encoding
::
Decode
(
is
,
&
codepoint
))
return
false
;
count
++
;
}
*
outCount
=
count
;
return
true
;
}
RAPIDJSON_NAMESPACE_END
#if defined(__GNUC__) || defined(_MSV_VER)
...
...
include/rapidjson/schema.h
View file @
e33049d2
...
...
@@ -428,8 +428,13 @@ public:
if
((
type_
&
(
1
<<
kStringSchemaType
))
==
0
)
return
false
;
if
(
length
<
minLength_
||
length
>
maxLength_
)
return
false
;
//if (length < minLength_ || length > maxLength_)
// return false;
if
(
minLength_
!=
0
||
maxLength_
!=
SizeType
(
~
0
))
{
SizeType
count
;
if
(
CountStringCodePoint
<
Encoding
>
(
str
,
length
,
&
count
)
&&
(
count
<
minLength_
||
count
>
maxLength_
))
return
false
;
}
#if RAPIDJSON_SCHEMA_HAS_REGEX
if
(
pattern_
&&
!
IsPatternMatch
(
*
pattern_
,
str
,
length
))
...
...
test/unittest/encodingstest.cpp
View file @
e33049d2
...
...
@@ -424,3 +424,14 @@ TEST(EncodingsTest, UTF32) {
}
}
}
TEST
(
EncodingsTest
,
CountStringCodePoint
)
{
SizeType
count
;
EXPECT_TRUE
(
CountStringCodePoint
<
UTF8
<>
>
(
""
,
0
,
&
count
));
EXPECT_EQ
(
0u
,
count
);
EXPECT_TRUE
(
CountStringCodePoint
<
UTF8
<>
>
(
"Hello"
,
5
,
&
count
));
EXPECT_EQ
(
5u
,
count
);
EXPECT_TRUE
(
CountStringCodePoint
<
UTF8
<>
>
(
"
\xC2\xA2\xE2\x82\xAC\xF0\x9D\x84\x9E
"
,
9
,
&
count
));
// cents euro G-clef
EXPECT_EQ
(
3u
,
count
);
EXPECT_FALSE
(
CountStringCodePoint
<
UTF8
<>
>
(
"
\xC2\xA2\xE2\x82\xAC\xF0\x9D\x84\x9E\x80
"
,
10
,
&
count
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment