Fixed Issue 44 SetStringRaw doesn't work with wchar_t
git-svn-id: https://rapidjson.googlecode.com/svn/trunk@65 c5894555-1306-4e8d-425f-1f6f381ee07c
This commit is contained in:
parent
4fdd805c7d
commit
821c6ab73c
@ -650,9 +650,9 @@ private:
|
|||||||
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
|
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
|
||||||
RAPIDJSON_ASSERT(s != NULL);
|
RAPIDJSON_ASSERT(s != NULL);
|
||||||
flags_ = kCopyStringFlag;
|
flags_ = kCopyStringFlag;
|
||||||
data_.s.str = (Ch *)allocator.Malloc(length + 1);
|
data_.s.str = (Ch *)allocator.Malloc((length + 1) * sizeof(Ch));
|
||||||
data_.s.length = length;
|
data_.s.length = length;
|
||||||
memcpy((void*)data_.s.str, s, length);
|
memcpy((void*)data_.s.str, s, length * sizeof(Ch));
|
||||||
((Ch*)data_.s.str)[length] = '\0';
|
((Ch*)data_.s.str)[length] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,3 +67,18 @@ TEST(Document, AcceptWriter) {
|
|||||||
|
|
||||||
EXPECT_EQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}", os.str());
|
EXPECT_EQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}", os.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 44: SetStringRaw doesn't work with wchar_t
|
||||||
|
TEST(Document, UTF16_Document) {
|
||||||
|
GenericDocument< UTF16<> > json;
|
||||||
|
json.Parse<kParseValidateEncodingFlag>(L"[{\"created_at\":\"Wed Oct 30 17:13:20 +0000 2012\"}]");
|
||||||
|
|
||||||
|
ASSERT_TRUE(json.IsArray());
|
||||||
|
GenericValue< UTF16<> >& v = json[0u];
|
||||||
|
ASSERT_TRUE(v.IsObject());
|
||||||
|
|
||||||
|
GenericValue< UTF16<> >& s = v[L"created_at"];
|
||||||
|
ASSERT_TRUE(s.IsString());
|
||||||
|
|
||||||
|
EXPECT_EQ(0, wcscmp(L"Wed Oct 30 17:13:20 +0000 2012", s.GetString()));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user