Skip to content

meaning of end in find(key, end) #302

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

Closed
cdunn2001 opened this issue Jul 7, 2015 · 2 comments
Closed

meaning of end in find(key, end) #302

cdunn2001 opened this issue Jul 7, 2015 · 2 comments
Labels

Comments

@cdunn2001
Copy link
Contributor

Bob wrote:

I'm using v1.6.2 of the jsoncpp library on aWin32 platform. All's well, I'm able to parse json and access Json:Values successfully using v.["firstname"] etc.

Q: How do I find a Json:Value by name in a json structure? In the documentation I've found:

Value const * Json::Value::find ( char const *key,char const *end ) const

but it doesn't specify what 'end' is. I've tried "", NULL etc, but it's throwing exceptions if I try to access the Value it returns.

Good question. We should clarify the docs, and maybe rename key to begin.

end is similar to begin/end in STL. It is one past the end of your string. If you have a null-terminated array, you can do this:

v.find(mycstring, mystring + strlen(mycstring));

WIth a std::string:

v.find(mystdstring.begin(), mystdstring.end());

Should I even be trying to find things this way?

Yes, it's the right API. The reason for the oddness is that we do not want anyone to rely on null-terminated c-strings, since they preclude UTF-8 with embedded zeroes.

@b06stiles
Copy link

Thanks - those suggestions work nicely. However I'm also finding that find is returning bool rather than the Value I'm trying to find. This is the reason I'm throwing exceptions when trying to access members. Is this correct? If so it might be helpful to update the documentation with this also. (I think I should be using get or one of the [] operators instead. I'll get the hang of this eventually!)

cdunn2001 added a commit that referenced this issue Jul 11, 2015
@cdunn2001
Copy link
Contributor Author

According the source-code, find() definitely does not return bool. It returns NULL on failure, so it acts like bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants