Beispiel #1
0
static int parseAndSaveValueTree(const JSONCPP_STRING& input,
                                 const JSONCPP_STRING& actual,
                                 const JSONCPP_STRING& kind,
                                 const Json::Features& features,
                                 bool parseOnly,
                                 Json::Value* root)
{
  Json::Reader reader(features);
  bool parsingSuccessful = reader.parse(input.data(), input.data() + input.size(), *root);
  if (!parsingSuccessful) {
    printf("Failed to parse %s file: \n%s\n",
           kind.c_str(),
           reader.getFormattedErrorMessages().c_str());
    return 1;
  }
  if (!parseOnly) {
    FILE* factual = fopen(actual.c_str(), "wt");
    if (!factual) {
      printf("Failed to create %s actual file.\n", kind.c_str());
      return 2;
    }
    printValueTree(factual, *root);
    fclose(factual);
  }
  return 0;
}
    Json::Value getDOM(std::string const& path)    {
      JSONCPP_STRING input = readInputTestFile(path.c_str());
      if (input.empty())      {
        throw std::runtime_error("Empty input file");
      }

      Json::Features mode = Json::Features::strictMode();
      mode.allowComments_ = true;
      Json::Value root;

      Json::Reader reader(mode);
      bool parsingSuccessful = reader.parse(input.data(), input.data() + input.size(), root);
      if (!parsingSuccessful)      {
        throw std::runtime_error(
          std::string("Failed to parse file: ") +
          reader.getFormattedErrorMessages());
      }
      return root;
    }
Beispiel #3
0
Value::Value(const JSONCPP_STRING& value) {
  initBasic(stringValue, true);
  value_.string_ =
      duplicateAndPrefixStringValue(value.data(), static_cast<unsigned>(value.length()));
}
Beispiel #4
0
bool Value::isMember(JSONCPP_STRING const& key) const
{
  return isMember(key.data(), key.data() + key.length());
}
Beispiel #5
0
bool Value::removeMember(JSONCPP_STRING const& key, Value* removed)
{
  return removeMember(key.data(), key.data() + key.length(), removed);
}
Beispiel #6
0
Value Value::get(JSONCPP_STRING const& key, Value const& defaultValue) const
{
  return get(key.data(), key.data() + key.length(), defaultValue);
}