Esempio n. 1
0
JsonNode JsonReader::ParseValue() {

   this->SkipWhiteSpaces();
   JsonNode node;

   /* String */
   if (*m_data == '"' || *m_data == '\'') {
      std::string string = this->ParseString();
      node.SetValue(std::move(string));
      node.SetType(JsonNode::Type::Value);
   }

   /* Number */
   else if ((*m_data >= '0' && *m_data <= '9') || *m_data == '-') {
      Any value = this->ParseNumber();
      node.SetValue(std::move(value));
      node.SetType(JsonNode::Type::Value);
   }

   /* Object */
   else if (*m_data == '{') {
      node = this->ParseObject();
      node.SetType(JsonNode::Type::Object);
   }

   /* Array */
   else if (*m_data == '[') {
      node = this->ParseArray();
      node.SetType(JsonNode::Type::Array);
   } else if (std::strncmp(m_data, "true", 4) == 0 ||
              std::strncmp(m_data, "TRUE", 4) == 0) {
      node.SetValue(true);
      node.SetType(JsonNode::Type::Value);
      m_data += 4;
   } else if (std::strncmp(m_data, "false", 5) == 0 ||
              std::strncmp(m_data, "FALSE", 5) == 0) {
      node.SetValue(false);
      node.SetType(JsonNode::Type::Value);
      m_data += 5;
   } else if (std::strncmp(m_data, "null", 4) == 0 ||
              std::strncmp(m_data, "NULL", 4) == 0) {
      node.SetValue(nullptr);
      node.SetType(JsonNode::Type::Value);
      m_data += 4;
   } else {
      PrintError(
          "Syntax Error: Expected a String, Number, Bool, Object, Array or "
          "null.");
   }

   return node;
}