join.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* join.cpp - merge list into string
  2. * Copyright (C) 2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <boost/algorithm/string/join.hpp>
  18. #include <core/node_info/macros.h>
  19. #include <core/node/new_node.h>
  20. #include <core/node/list.h>
  21. namespace rainynite::core::nodes {
  22. class JoinStringList :
  23. public NewNode<
  24. JoinStringList,
  25. string,
  26. types::Only<string>,
  27. types::Only<vector<string>>
  28. >
  29. {
  30. DOC_STRING(
  31. "Merge list into string with separator."
  32. )
  33. NODE_PROPERTIES("separator", "strings")
  34. COMPLEX_DEFAULT_VALUES(make_value<string>(), make_node<ListValue<string>>())
  35. PROPERTY(separator)
  36. PROPERTY(strings)
  37. protected:
  38. string get(shared_ptr<Context> ctx) const override {
  39. auto strings = strings_value<vector<string>>(ctx);
  40. auto separator = separator_value<string>(ctx);
  41. return boost::algorithm::join(strings, separator);
  42. }
  43. };
  44. REGISTER_NODE(JoinStringList);
  45. } // namespace rainynite::core::nodes