Fix clang compilation and a memory leak
This commit is contained in:
parent
1948fb5786
commit
761561a28d
@ -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
|
RAPIDJSON_NAMESPACE_END
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(_MSV_VER)
|
#if defined(__GNUC__) || defined(_MSV_VER)
|
||||||
|
@ -33,6 +33,22 @@ inline SizeType StrLen(const Ch* s) {
|
|||||||
return SizeType(p - 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
|
} // namespace internal
|
||||||
RAPIDJSON_NAMESPACE_END
|
RAPIDJSON_NAMESPACE_END
|
||||||
|
|
||||||
|
@ -306,6 +306,7 @@ public:
|
|||||||
#if RAPIDJSON_SCHEMA_HAS_REGEX
|
#if RAPIDJSON_SCHEMA_HAS_REGEX
|
||||||
delete [] patternProperties_;
|
delete [] patternProperties_;
|
||||||
#endif
|
#endif
|
||||||
|
delete additionalItemsSchema_;
|
||||||
delete itemsList_;
|
delete itemsList_;
|
||||||
for (SizeType i = 0; i < itemsTupleCount_; i++)
|
for (SizeType i = 0; i < itemsTupleCount_; i++)
|
||||||
delete itemsTuple_[i];
|
delete itemsTuple_[i];
|
||||||
@ -431,7 +432,7 @@ public:
|
|||||||
// return false;
|
// return false;
|
||||||
if (minLength_ != 0 || maxLength_ != SizeType(~0)) {
|
if (minLength_ != 0 || maxLength_ != SizeType(~0)) {
|
||||||
SizeType count;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ set(UNITTEST_SOURCES
|
|||||||
readertest.cpp
|
readertest.cpp
|
||||||
schematest.cpp
|
schematest.cpp
|
||||||
simdtest.cpp
|
simdtest.cpp
|
||||||
|
strfunctest.cpp
|
||||||
stringbuffertest.cpp
|
stringbuffertest.cpp
|
||||||
strtodtest.cpp
|
strtodtest.cpp
|
||||||
unittest.cpp
|
unittest.cpp
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
|
31
test/unittest/strfunctest.cpp
Normal file
31
test/unittest/strfunctest.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// 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));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user