Advertisement
Guest User

Untitled

a guest
Aug 30th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #pragma once
  2.  
  3. #ifndef COMMAND_INTERFACE_EXTENDED_H
  4. #define COMMAND_INTERFACE_EXTENDED_H
  5.  
  6. #include <string>
  7. #include <cstring>
  8. #include <vector>
  9.  
  10. #include "TextTransform.h"
  11. #include "CommandInterface.h"
  12.  
  13. const size_t MAX_TEXT_SIZE = 30;
  14.  
  15. class CommandInterfaceExtended : public CommandInterface {
  16.  
  17. public:
  18.  
  19. CommandInterfaceExtended(std::string& text) : CommandInterface(text) {}
  20.  
  21. // CUT TRANSFORM
  22. class CutTransform : public TextTransform {
  23. void invokeOn(std::string& text, int startIndex, int endIndex) override {
  24. for (int i = startIndex; i < endIndex; ++i) {
  25. CommandInterfaceExtended::_lastCut += text[i];
  26. }
  27. text.erase(text.begin() + startIndex, text.begin() + endIndex);
  28. }
  29.  
  30. };
  31.  
  32. // PASTE TRANSFORM
  33. class PasteTransform : public CutTransform {
  34. void invokeOn(std::string& text, int startIndex, int endIndex) override {
  35. text.replace(text.begin() + startIndex, text.begin() + endIndex, CommandInterfaceExtended::_lastCut);
  36. }
  37. };
  38.  
  39. // INIT COMMANDS FUNCTION
  40. std::vector<Command> initCommands() override {
  41. std::vector<Command> commands;
  42.  
  43. commands.push_back(Command("cut", std::make_shared<CutTransform>()));
  44. commands.push_back(Command("paste", std::make_shared<PasteTransform>()));
  45.  
  46. //addig uppercase case, works as paste :?
  47. //commands.push_back(Command("uppercase", std::make_shared<PasteTransform>()));
  48.  
  49. return commands;
  50. }
  51. protected:
  52. static std::string _lastCut;
  53. };
  54.  
  55. #endif // COMMAND_INTERFACE_EXTENDED_H
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement