Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MyString::cleanUpPaddedHyphens(std::string &string_OUT)
- {
- //run cleanUpExtraSpaces() before cleaning padded hyphens.
- size_t index {0};
- std::vector<size_t> indexes_to_erase {};
- //search loop
- for (const char &character : string_OUT)
- {
- //look for an occurance of a digit followed by a space followed by a hyphen '5 -'
- if (isdigit(character) && string_OUT.substr(index + 1, 2) == " -")
- {
- //pre-space detected, add it to the erase list
- indexes_to_erase.push_back(index + 1); // +1 because the space is one character after the index
- }
- //look for an occurance of a hyphen followed by a space followed by a digit '- 7'
- if (string_OUT.substr(index, 2) == "- " && isdigit(string_OUT[index + 2]))
- {
- //post-space detected, add it to the erase list
- indexes_to_erase.push_back(index + 1);
- }
- index++;
- }
- //clean string from back to front to keep index numbers valid
- while (indexes_to_erase.empty() == false)
- {
- index = indexes_to_erase.back();
- indexes_to_erase.pop_back();
- string_OUT.erase(index, 1);
- //diag
- //std::cout << "\nremoving space at " << index << "\n";
- //end diag
- }
- //diag
- //std::cout << "\n" << string_OUT << "\n";
- //end diag
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement