-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse non-null-terminated strings / Parse with std::string #158
Comments
This seems fit your need On Thu, Oct 9, 2014 at 6:30 PM, Sean Leather [email protected]
Milo Yip http://www.cnblogs.com/miloyip/ |
You can do this already by using a An overload Parse(const Ch * str, size_t sz) {
const char* buf = (const char*) str;
size_t bufsz = sz * sizeof(Ch);
MemoryStream ms(buf, bufsz);
EncodedInputStream<Encoding, MemoryStream> is(ms);
ParseStream(is);
return *this;
} Don't know if this is reasonable to add to the core API. Edit: Oh, @miloyip was quicker. |
Great. Thanks, guys. |
Sorry to bring it up again guys, but do you have any plans of making this a part of the main API? How about a EDIT: |
I agree, that this might indeed be a useful addition. Feel free to prepare a pull-request (and/or add it to your own fork) based on the following sketch (untested!): // add required headers
template <unsigned parseFlags, typename SourceEncoding>
GenericDocument& Parse(const Ch * str, SizeType sz) {
RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
const char* buf = (const char*) str;
size_t bufsz = sz * sizeof(Ch);
MemoryStream ms(buf, bufsz);
EncodedInputStream<SourceEncoding, MemoryStream> is(ms);
ParseStream<parseFlags, SourceEncoding>(is);
return *this;
}
template <unsigned parseFlags>
GenericDocument& Parse(const Ch * str, SizeType sz) {
return Parse<parseFlags, Encoding>(str, sz);
}
GenericDocument& Parse(const Ch * str, SizeType sz) {
return Parse<kParseDefaultFlags>(str, sz);
} Please add documentation and tests (e.g. to To support #if RAPIDJSON_HAS_STDSTRING
template <unsigned parseFlags, typename SourceEncoding>
GenericDocument& Parse(const std::basic_string<Ch>& str) {
return Parse<parseFlags, SourceEncoding>(str.data(), str.size());
}
template <unsigned parseFlags>
GenericDocument& Parse(const std::basic_string<Ch>& str) {
return Parse<parseFlags, Encoding>(str);
}
GenericDocument& Parse(const std::basic_string<Ch>& str) {
return Parse<kParseDefaultFlags>(str);
}
#endif // RAPIDJSON_HAS_STDSTRING
|
I would also like to see it in the interface. Since there's interest, I'll reopen this issue. @oranjuice In addition to @pah's suggestions, you might consider adding performance tests to |
Thanks guys. I'm not sure if I can get it to soon (if at all), but I'll try to find time. |
Are there any problems with using only I added this perf test:
And here are some of the results for comparison:
|
Can you try to check, whether adding a template <typename Encoding, typename InputByteStream>
struct StreamTraits<EncodedInputStream<Encoding, InputByteStream> > {
enum { copyOptimization = 1 };
}; I would prefer to keep the |
Absolutely. I didn't mean to suggest that we do otherwise. I was just curious if my suggestion actually made sense from a purely technical standpoint.
Sure, I'll try that. |
Technically, it should be sufficient to use a plain |
Thanks! That confirms my intuition. |
Note that SIMD whitespace skipping is also only made available for |
I don't see a way to safely do SIMD whitespace checking for a |
I am OK for PR for supporting |
std::string
std::string
This doesn't work with |
+1 ! I don't think it does - |
I would like to parse strings that are not null-terminated but do have a string length.
What's the best way to do that now? Implement the
Stream
concept? I guess it would involve something like copying theGenericStringStream
, adding a length-remaining member, and modifyingPeek()
to return'\0'
when the end is reached.I think this would be useful for RapidJSON in general. It could be exposed as overloaded
Parse(const Ch *, size_t)
andParseInsitu (Ch *, size_t)
methods.The text was updated successfully, but these errors were encountered: