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
b01093b1
Commit
b01093b1
authored
Jul 04, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes a compilation error in Reader when using encoded stream.
Added unit test for parsing EncodedStream to Document.
parent
a787e8a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
2 deletions
+56
-2
encodedstream.h
include/rapidjson/encodedstream.h
+1
-1
reader.h
include/rapidjson/reader.h
+1
-1
documenttest.cpp
test/unittest/documenttest.cpp
+54
-0
No files found.
include/rapidjson/encodedstream.h
View file @
b01093b1
...
...
@@ -30,7 +30,7 @@ public:
size_t
Tell
()
const
{
return
is_
.
Tell
();
}
// Not implemented
void
Put
(
Ch
c
)
{
RAPIDJSON_ASSERT
(
false
);
}
void
Put
(
Ch
)
{
RAPIDJSON_ASSERT
(
false
);
}
void
Flush
()
{
RAPIDJSON_ASSERT
(
false
);
}
Ch
*
PutBegin
()
{
RAPIDJSON_ASSERT
(
false
);
return
0
;
}
size_t
PutEnd
(
Ch
*
)
{
RAPIDJSON_ASSERT
(
false
);
return
0
;
}
...
...
include/rapidjson/reader.h
View file @
b01093b1
...
...
@@ -491,7 +491,7 @@ private:
InputStream
&
s
(
copy
.
s
);
if
(
parseFlags
&
kParseInsituFlag
)
{
Ch
*
head
=
s
.
PutBegin
();
typename
InputStream
::
Ch
*
head
=
s
.
PutBegin
();
ParseStringToStream
<
parseFlags
,
SourceEncoding
,
SourceEncoding
>
(
s
,
s
);
if
(
HasParseError
())
return
;
...
...
test/unittest/documenttest.cpp
View file @
b01093b1
#include "unittest.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/encodedstream.h"
#include "rapidjson/stringbuffer.h"
#include <sstream>
using
namespace
rapidjson
;
...
...
@@ -47,6 +50,57 @@ TEST(Document, Parse) {
EXPECT_EQ
(
i
+
1
,
a
[
i
].
GetUint
());
}
static
FILE
*
OpenEncodedFile
(
const
char
*
filename
)
{
char
buffer
[
1024
];
sprintf
(
buffer
,
"encodings/%s"
,
filename
);
FILE
*
fp
=
fopen
(
buffer
,
"rb"
);
if
(
!
fp
)
{
sprintf
(
buffer
,
"../../bin/encodings/%s"
,
filename
);
fp
=
fopen
(
buffer
,
"rb"
);
}
return
fp
;
}
TEST
(
Document
,
ParseStream_EncodedInputStream
)
{
// UTF8 -> UTF16
FILE
*
fp
=
OpenEncodedFile
(
"utf8.json"
);
char
buffer
[
256
];
FileReadStream
bis
(
fp
,
buffer
,
sizeof
(
buffer
));
EncodedInputStream
<
UTF8
<>
,
FileReadStream
>
eis
(
bis
);
GenericDocument
<
UTF16
<>
>
d
;
d
.
ParseStream
<
0
,
UTF8
<>
>
(
eis
);
EXPECT_FALSE
(
d
.
HasParseError
());
fclose
(
fp
);
wchar_t
expected
[]
=
L"I can eat glass and it doesn't hurt me."
;
GenericValue
<
UTF16
<>
>&
v
=
d
[
L"en"
];
EXPECT_TRUE
(
v
.
IsString
());
EXPECT_EQ
(
sizeof
(
expected
)
/
sizeof
(
wchar_t
)
-
1
,
v
.
GetStringLength
());
EXPECT_EQ
(
0
,
StrCmp
(
expected
,
v
.
GetString
()));
// UTF16 -> UTF8 in memory
StringBuffer
bos
;
typedef
EncodedOutputStream
<
UTF8
<>
,
StringBuffer
>
OutputStream
;
OutputStream
eos
(
bos
,
false
);
// Not writing BOM
Writer
<
OutputStream
,
UTF16
<>
,
UTF8
<>
>
writer
(
eos
);
d
.
Accept
(
writer
);
{
// Condense the original file and compare.
FILE
*
fp
=
OpenEncodedFile
(
"utf8.json"
);
FileReadStream
is
(
fp
,
buffer
,
sizeof
(
buffer
));
Reader
reader
;
StringBuffer
bos2
;
Writer
<
StringBuffer
>
writer
(
bos2
);
reader
.
Parse
(
is
,
writer
);
EXPECT_EQ
(
bos
.
GetSize
(),
bos2
.
GetSize
());
EXPECT_EQ
(
0
,
memcmp
(
bos
.
GetString
(),
bos2
.
GetString
(),
bos2
.
GetSize
()));
}
}
TEST
(
Document
,
Swap
)
{
Document
d1
;
Document
::
AllocatorType
&
a
=
d1
.
GetAllocator
();
...
...
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