This commit is contained in:
cyborg1811m 2023-12-30 21:31:16 +01:00
commit 892c5b1970
1 changed files with 29 additions and 0 deletions

29
main.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <algorithm>
#include <iostream>
#include <limits>
int main() {
std::cout << "Enter To-Minify: \n"
"Press Ctrl+d (Unix) or Ctrl+z followed by Enter on a new line (Windows) to confirm input\n"
"Press Ctrl+c or enter an empty string to exit" << std::endl;
std::string input;
std::getline(std::cin, input, static_cast<char>(EOF));
std::cin.clear();
if (input.empty())
return 0;
std::replace_if(input.begin(), input.end(), [] (char c) { return isspace(c); }, ' ');
std::string output;
std::unique_copy(input.begin(), input.end(), std::back_insert_iterator<std::string>(output),
[](char i, char in){ return std::isspace(i) && std::isspace(in); });
std::cout << "----------------------------------------\n";
std::cout << output << "\n" << std::endl;
return 0;
}