Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include "StringConcatenator.h"
- using namespace std;
- StringConcatenator::StringConcatenator() = default;
- StringConcatenator::~StringConcatenator() = default;
- string StringConcatenator::concatenate(const ConcatenateStrategy strategy,
- const char* left,
- const size_t leftSize,
- const char* right,
- const size_t rightSize) const
- {
- string output = "";
- if(strategy == ConcatenateStrategy::LEFT_1_RIGHT_1)
- {
- string currentLeft = left;
- string currentRight = right;
- for(size_t i = 0; i < leftSize + rightSize; ++i)
- {
- if(currentLeft.empty())
- {
- output.append(currentRight);
- break;
- }
- if(currentRight.empty())
- {
- output.append(currentLeft);
- break;
- }
- output.append(sizeof(char), left[i]);
- currentLeft.erase(currentLeft.begin() + 0);
- output.append(sizeof(char), right[i]);
- currentRight.erase(currentRight.begin() + 0);
- }
- return output;
- }
- else if(strategy == ConcatenateStrategy::LEFT_2_RIGHT_1)
- {
- string currentLeft = left;
- string currentRight = right;
- for(size_t i = 0; i < leftSize + rightSize;)
- {
- if(currentLeft.empty())
- {
- output.append(currentRight);
- break;
- }
- if(currentRight.empty())
- {
- output.append(currentLeft);
- break;
- }
- output.append(sizeof(char), currentLeft[i]);
- currentLeft.erase(currentLeft.begin() + 0);
- output.append(sizeof(char), currentLeft[i]);
- currentLeft.erase(currentLeft.begin() + 0);
- output.append(sizeof(char), currentRight[i]);
- currentRight.erase(currentRight.begin() + 0);
- i = 0;
- }
- return output;
- }
- else
- {
- string currentLeft = left;
- string currentRight = right;
- for(size_t i = 0; i < leftSize + rightSize;)
- {
- if(currentLeft.empty())
- {
- output.append(currentRight);
- break;
- }
- if(currentRight.empty())
- {
- output.append(currentLeft);
- break;
- }
- output.append(sizeof(char), currentLeft[i]);
- currentLeft.erase(currentLeft.begin() + 0);
- output.append(sizeof(char), currentRight[i]);
- currentRight.erase(currentRight.begin() + 0);
- output.append(sizeof(char), currentRight[i]);
- currentRight.erase(currentRight.begin() + 0);
- i = 0;
- }
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement