| 207 | { |
| 208 | public: |
| 209 | explicit Strings(Menu* menu) |
| 210 | { |
| 211 | auto subMenu = make_unique<Menu>(Name(), "Enter the " + Name() + " plugin menu"); |
| 212 | subMenu->Insert( |
| 213 | "reverse", {"string_to_revert"}, |
| 214 | [](std::ostream& out, const string& arg) |
| 215 | { |
| 216 | string copy(arg); |
| 217 | std::reverse(copy.begin(), copy.end()); |
| 218 | out << copy << "\n"; |
| 219 | }, |
| 220 | "Print the reverse string" ); |
| 221 | |
| 222 | subMenu->Insert( |
| 223 | "upper", |
| 224 | [](std::ostream& out, string arg) |
| 225 | { |
| 226 | std::transform(arg.begin(), arg.end(),arg.begin(), ::toupper); |
| 227 | out << arg << "\n"; |
| 228 | }, |
| 229 | "Print the string in uppercase" ); |
| 230 | subMenu->Insert( |
| 231 | "sort", {"list of strings separated by space"}, |
| 232 | [](std::ostream& out, std::vector<std::string> data) |
| 233 | { |
| 234 | std::sort(data.begin(), data.end()); |
| 235 | out << "sorted list: "; |
| 236 | std::copy(data.begin(), data.end(), std::ostream_iterator<std::string>(out, " ")); |
| 237 | out << "\n"; |
| 238 | }, |
| 239 | "Alphabetically sort a list of words" ); |
| 240 | menuHandler = menu->Insert(std::move(subMenu)); |
| 241 | } |
| 242 | ~Strings() override |
| 243 | { |
| 244 | menuHandler.Remove(); |