+++ /dev/null
-/*
- * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdexcept>
-
-#include "action/utils/json_parser.hh"
-#include "common/utils/logging.hh"
-
-namespace action {
-namespace utils {
-
-JsonParser::JsonParser(std::string json_str)
- : json_str_(json_str) {
- LOG(DEBUG) << "ParseStr const";
-
- std::size_t pos = 0;
- std::size_t lpos = 0;
- std::string params;
-
- // remove {}
- pos = json_str_.find("{");
- lpos = json_str_.rfind("}");
- json_str_ = json_str_.substr(pos + 1, lpos - pos - 1);
-
- // seperate params
- pos = json_str_.find("{");
- lpos = json_str_.rfind("}");
- params = json_str_.substr(pos + 1, lpos - pos - 1);
- json_str_.replace(pos + 1, lpos - pos - 1, " ");
-
- // make nodes
- while(true) {
- pos = json_str_.find(",");
-
- if (pos == std::string::npos)
- break;
-
- std::string sub_ = json_str_.substr(0, pos);
- std::size_t spos = sub_.find(":");
- std::string key = sub_.substr(1, spos - 2);
- sub_ = sub_.substr(spos + 1);
- std::string value = sub_.substr(1, sub_.length() - 2);
-
- nodes_[key] = value;
-
- // LOG(DEBUG) << key << " : " << value;
-
- json_str_ = json_str_.substr(pos + 1);
- }
-
-// LOG(DEBUG) << params;
-
- std::size_t compos = 0;
-
- // make params
- while(true) {
- pos = params.find("{");
- lpos = params.find("}");
-
- std::string key = params.substr(1, pos - 3);
- std::string value = params.substr(pos + 1, lpos - pos - 1);
-
- // LOG(DEBUG) << key << " : " << value;
-
-
- std::size_t subpos = 0;
- std::size_t nextpos = 0;
- std::size_t compos_ = 0;
- std::map<std::string, std::string> mvalue;
-
- // make param value
- while(true) {
- // LOG(DEBUG) << value;
-
- subpos = value.find("\"");
- nextpos = value.find("\"", subpos + 1);
-
- std::string subkey = value.substr(1, nextpos - 1);
-
- subpos = value.find("\"", nextpos + 1);
- nextpos = value.find("\"", subpos + 1);
-
- std::string subval = value.substr(subpos + 1, nextpos - subpos - 1);
-
- mvalue[subkey] = subval;
-
- compos_ = value.find(",", nextpos);
- if (compos_ == std::string::npos)
- break;
-
- value = value.substr(compos_ + 1);
- }
- params_[key] = mvalue;
-
- compos = params.find(",", lpos);
- if (compos == std::string::npos)
- break;
-
- params = params.substr(lpos + 2);
- }
-
- LOG(DEBUG) << "ParseStr const end";
-}
-
-std::string JsonParser::GetAppId() {
- return nodes_["appId"];
-}
-
-std::string JsonParser::GetName() {
- return nodes_["name"];
-}
-
-std::string JsonParser::GetDescription() {
- return nodes_["desc"];
-}
-
-std::string JsonParser::GetType() {
- return nodes_["type"];
-}
-
-std::string JsonParser::GetVersion() {
- return nodes_["version"];
-}
-
-std::string JsonParser::GetRequiredPrivilege() {
- return nodes_["required-privileges"];
-}
-
-std::string JsonParser::GetReturns() {
- return nodes_["required-privileges"];
-}
-
-std::map<std::string, std::map<std::string, std::string>> JsonParser::GetParameters() {
- return params_;
-}
-
-} // namespace utils
-} // namespace action
+++ /dev/null
-/*
- * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef JSON_PARSER_H_
-#define JSON_PARSER_H_
-
-// #include <json/json.h>
-
-#include <string>
-#include <map>
-
-namespace action {
-namespace utils {
-
-/* temporary parser */
-/* need to be changed to use json */
-
-class JsonParser {
- public:
- JsonParser(std::string json_str);
- ~JsonParser() = default;
-
- std::string GetAppId();
- std::string GetName();
- std::string GetDescription();
- std::string GetType();
- std::string GetVersion();
- std::string GetRequiredPrivilege();
- std::string GetReturns();
- std::map<std::string, std::map<std::string, std::string>> GetParameters();
-
- private:
- std::string json_str_;
- std::map<std::string, std::string> nodes_;
- std::map<std::string, std::map<std::string, std::string>> params_;
-};
-
-} // namespace action
-} // namespace utils
-
-#endif //