Skip to content
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

Scanf string using scanset (character class) #57

Open
Harvie opened this issue Jan 23, 2020 · 0 comments
Open

Scanf string using scanset (character class) #57

Harvie opened this issue Jan 23, 2020 · 0 comments

Comments

@Harvie
Copy link

Harvie commented Jan 23, 2020

Hello,
i've found that unlike original scanf(), the json_scanf() does not support "scanset" feature. Eg.:

json_scanf(in, sizeof(in), "{ str:%30[0-9a-zA-Z ] }", out);

should scan string of up to 30 characers from set [0-9a-zA-Z ] = both cases of alphanumeric characters and space. But it does not work in frozen.

Have you considered implementing this useful feature of scanf() to json_scanf()?

Also it would be nice to have some way to get pointer and length of escaped JSON string. sometimes there's no need to unescape so i would love to have way to parse string without using dynamic memory allocation, so it's faster and i don't have to free() anything...

Something like this would be great:

json_scanf(in, sizeof(in), "{ str:%.*s }", out.len, out.ptr);

i've used %.*s because that's how printf() handles situation where you want to pass string length along with pointer... But maybe %S would be nice option as well. in such case json_scanf() should return whole length of string minus the quotes (but still json escaped).

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

No branches or pull requests

1 participant