-
Notifications
You must be signed in to change notification settings - Fork 779
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
Make jsmntype_t values bit flags #108
Conversation
This way one can easily check whether a token is one of a few types: if (token.type & (JSMN_ARRAY | JSMN_OBJECT)) // do stuff with array or object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work as the bitshifting is wrong. To achieve the pullrequests intent, you could instead define the enum like:
typedef enum {
JSMN_UNDEFINED = (1<<0),
JSMN_OBJECT = (1<<1),
JSMN_ARRAY = (1<<2),
JSMN_STRING = (1<<3),
JSMN_PRIMITIVE = (1<<4)
} jsmntype_t;
Oops, my bad! Guess that's what you get for doing a pull request through github's online interface... Thanks for spotting, fixed it in 2nd commit. |
I still think it's an interesting concept that's worth considering. It can't be pulled at this point but I'll keep this open just so I won't easily forget about it. |
Don't know why the PR couldn't be merged anymore... Fixed the "conflicts" so it can be pulled again. |
This goes into my bucket of things to actually add to jsmn. Thanks for the fix |
Awesome, thanks! Didn't actually change anything in the merge commit I think... PS Oh wait, looks like indentation whitespace has changed. |
I want this feature too, but please leave JSMN_UNDEFINED as 0, otherwise
|
I want this feature because on some architectures (such as ARM), less instructions are required for |
@alexhenrie that's a good point about leaving |
Something similar is already available in the experimental branch, @alexhenrie. Due to extremely slow development there I will just merge this pull request with the main branch. I do not see any possible incompatibilities at this point. This definition of jsmntype is compatible with any usage I'm aware of and also brings in possibility to test more efficiently for multiple types. |
There are no issues introduced based on the tests either. |
Thank you very much! |
Merge pull request zserge#108 from olmokramer/patch-1
The only possible incompatibility is that this is an ABI breaking change. But since Still, it might be worth making the next release of jsmn a v2.0.0 release, just to be on the safe side. It looks like there are some OpenSUSE packages that are bundling |
This way one can easily check whether a token is either of multiple types, e.g.: