Skip to content

Scanf string using scanset (character class) #57

Open
@Harvie

Description

@Harvie

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions