1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
12 #include "cmStringAlgorithms.h"
20 using Location
= struct
27 using JsonPair
= std::pair
<const std::string
, const Json::Value
*>;
28 cmJSONState() = default;
29 cmJSONState(const std::string
& filename
, Json::Value
* root
);
30 void AddError(std::string
const& errMsg
);
31 void AddErrorAtValue(std::string
const& errMsg
, const Json::Value
* value
);
32 void AddErrorAtOffset(std::string
const& errMsg
, std::ptrdiff_t offset
);
33 std::string
GetErrorMessage(bool showContext
= true);
35 std::string
key_after(std::string
const& key
);
36 const Json::Value
* value_after(std::string
const& key
);
37 void push_stack(std::string
const& key
, const Json::Value
* value
);
43 Error(Location loc
, std::string errMsg
)
45 , message(std::move(errMsg
)){};
46 Error(std::string errMsg
)
47 : location({ -1, -1 })
48 , message(std::move(errMsg
)){};
49 std::string
GetErrorMessage() const
51 std::string output
= message
;
52 if (location
.line
> 0) {
53 output
= cmStrCat("Error: @", location
.line
, ",", location
.column
,
58 Location
GetLocation() const { return location
; }
65 std::vector
<JsonPair
> parseStack
;
66 std::vector
<Error
> errors
;
68 bool allowComments
= false;
71 std::string
GetJsonContext(Location loc
);
72 Location
LocateInDocument(ptrdiff_t offset
);