/** * src/uml/command_parser.cc * * Copyright (c) 2021 Bartek Kryza * * 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 "command_parser.h" #include "util/util.h" #include #include namespace clanguml { namespace command_parser { const std::string note::label = "note"; const std::string skip::label = "skip"; const std::string skip_relationship::label = "skiprelationship"; const std::string style::label = "style"; const std::string aggregation::label = "aggregation"; std::shared_ptr command::from_string(std::string_view c) { if (c.find(note::label) == 0) { return note::from_string(c); } else if (c.find(skip::label) == 0) { return skip::from_string(c); } else if (c.find(skip_relationship::label) == 0) { return skip_relationship::from_string(c); } else if (c.find(style::label) == 0) { return style::from_string(c); } else if (c.find(aggregation::label) == 0) { return aggregation::from_string(c); } return {}; } std::shared_ptr note::from_string(std::string_view c) { auto res = std::make_shared(); auto it = c.begin(); std::advance(it, note::label.size()); if (*it != '[') return {}; std::advance(it, 1); auto pos = std::distance(c.begin(), it); res->position = c.substr(pos, c.find("]", pos) - pos); std::advance(it, res->position.size() + 1); pos = std::distance(c.begin(), it); res->text = c.substr(pos, c.find("}", pos) - pos); res->position = util::trim(res->position); res->text = util::trim(res->text); return res; } std::shared_ptr skip::from_string(std::string_view c) { auto res = std::make_shared(); return res; } std::shared_ptr skip_relationship::from_string(std::string_view c) { auto res = std::make_shared(); return res; } std::shared_ptr style::from_string(std::string_view c) { auto res = std::make_shared