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
761561a2
Commit
761561a2
authored
May 07, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix clang compilation and a memory leak
parent
1948fb57
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
28 deletions
+51
-28
encodings.h
include/rapidjson/encodings.h
+0
-16
strfunc.h
include/rapidjson/internal/strfunc.h
+16
-0
schema.h
include/rapidjson/schema.h
+2
-1
CMakeLists.txt
test/unittest/CMakeLists.txt
+1
-0
encodingstest.cpp
test/unittest/encodingstest.cpp
+0
-11
strfunctest.cpp
test/unittest/strfunctest.cpp
+32
-0
No files found.
include/rapidjson/encodings.h
View file @
761561a2
...
...
@@ -616,22 +616,6 @@ 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/internal/strfunc.h
View file @
761561a2
...
...
@@ -33,6 +33,22 @@ inline SizeType StrLen(const Ch* s) {
return
SizeType
(
p
-
s
);
}
//! 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
;
}
}
// namespace internal
RAPIDJSON_NAMESPACE_END
...
...
include/rapidjson/schema.h
View file @
761561a2
...
...
@@ -306,6 +306,7 @@ public:
#if RAPIDJSON_SCHEMA_HAS_REGEX
delete
[]
patternProperties_
;
#endif
delete
additionalItemsSchema_
;
delete
itemsList_
;
for
(
SizeType
i
=
0
;
i
<
itemsTupleCount_
;
i
++
)
delete
itemsTuple_
[
i
];
...
...
@@ -431,7 +432,7 @@ public:
// return false;
if
(
minLength_
!=
0
||
maxLength_
!=
SizeType
(
~
0
))
{
SizeType
count
;
if
(
CountStringCodePoint
<
Encoding
>
(
str
,
length
,
&
count
)
&&
(
count
<
minLength_
||
count
>
maxLength_
))
if
(
internal
::
CountStringCodePoint
<
Encoding
>
(
str
,
length
,
&
count
)
&&
(
count
<
minLength_
||
count
>
maxLength_
))
return
false
;
}
...
...
test/unittest/CMakeLists.txt
View file @
761561a2
...
...
@@ -13,6 +13,7 @@ set(UNITTEST_SOURCES
readertest.cpp
schematest.cpp
simdtest.cpp
strfunctest.cpp
stringbuffertest.cpp
strtodtest.cpp
unittest.cpp
...
...
test/unittest/encodingstest.cpp
View file @
761561a2
...
...
@@ -424,14 +424,3 @@ 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
));
}
test/unittest/strfunctest.cpp
0 → 100644
View file @
761561a2
// Tencent is pleased to support the open source community by making RapidJSON available.
//
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
//
// Licensed under the MIT License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#include "unittest.h"
#include "rapidjson/internal/strfunc.h"
using
namespace
rapidjson
;
using
namespace
rapidjson
::
internal
;
TEST
(
StrFunc
,
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
));
}
\ No newline at end of file
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