Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmJSONState.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <cstddef>
8
#include <string>
9
#include <utility>
10
#include <vector>
11
12
namespace Json {
13
class Value;
14
}
15
16
class cmJSONState
17
{
18
  using Location = struct
19
  {
20
    int line;
21
    int column;
22
  };
23
24
public:
25
  using JsonPair = std::pair<std::string const, Json::Value const*>;
26
0
  cmJSONState() = default;
27
  cmJSONState(std::string jsonFile, Json::Value* root);
28
  void AddError(std::string const& errMsg);
29
  void AddErrorAtValue(std::string const& errMsg, Json::Value const* value);
30
  void AddErrorAtOffset(std::string const& errMsg, std::ptrdiff_t offset);
31
  std::string GetErrorMessage(bool showContext = true);
32
  std::string key();
33
  std::string key_after(std::string const& key);
34
  Json::Value const* value_after(std::string const& key);
35
  void push_stack(std::string const& key, Json::Value const* value);
36
  void pop_stack();
37
38
  class Error
39
  {
40
  public:
41
    Error(Location loc, std::string errMsg)
42
0
      : location(loc)
43
0
      , message(std::move(errMsg)) {};
44
    Error(std::string errMsg)
45
0
      : location({ -1, -1 })
46
0
      , message(std::move(errMsg)) {};
47
0
    std::string GetErrorMessage() const { return message; }
48
0
    Location GetLocation() const { return location; }
49
50
  private:
51
    Location location;
52
    std::string message;
53
  };
54
55
  std::vector<JsonPair> parseStack;
56
  std::vector<Error> errors;
57
  std::string doc;
58
  bool allowComments = false;
59
60
private:
61
  std::string GetJsonContext(Location loc);
62
  Location LocateInDocument(ptrdiff_t offset);
63
  std::string Filename;
64
};