Thanks to visit codestin.com
Credit goes to github.com

Skip to content

No way to get location of string key in a parsed file #1283

@KyleFromKitware

Description

@KyleFromKitware

Is your feature request related to a problem? Please describe.
I would like to be able to determine exactly where in a file a string key in an object came from, so that I can emit useful error messages related to the contents of the key itself (not the value associated with it).

Describe the solution you'd like
I would like to add four new member functions to Json::Value:

  void setKeyOffsetStart(const char* begin, const char* end, ptrdiff_t start);
  void setKeyOffsetLimit(const char* begin, const char* end, ptrdiff_t limit);
  ptrdiff_t getKeyOffsetStart(const char* begin, const char* end) const;
  ptrdiff_t getKeyOffsetLimit(const char* begin, const char* end) const;

These are based on, and functionally similar to, setOffsetStart(), setOffsetLimit(), getOffsetStart(), and getOffsetLimit().

Describe alternatives you've considered
I could use getOffsetStart() and getOffsetLimit() to get the location of the value associated with the key, which would at least put the user in the vicinity of the key that they need to inspect. However, getting the location of the key itself (in case it's on a different line than the value) would be more ideal.

Additional context
I am trying to make some of CMake's error messages regarding errors in JSON files more detailed and helpful, but am running into limits from jsoncpp.

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