diff --git a/src/uml/command_parser.cc b/src/uml/command_parser.cc new file mode 100644 index 00000000..f6b945c6 --- /dev/null +++ b/src/uml/command_parser.cc @@ -0,0 +1,143 @@ +/** + * 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 { + +std::shared_ptr command::from_string(std::string_view c) +{ + if (c.find("note") == 0) { + return note::from_string(c); + } + else if (c.find("style") == 0) { + return style::from_string(c); + } + else if (c.find("aggregation") == 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(); + // Skip 'note' + std::advance(it, 4); + + 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 style::from_string(std::string_view c) +{ + auto res = std::make_shared