-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
37 lines (29 loc) · 907 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <regex>
#include <string>
#include <iostream>
#include <algorithm>
std::string
minify(std::string str) {
// Remove newlines
std::erase(str, '\n');
// Remove spacing around special characters
str = std::regex_replace(str, std::regex("\\s*([{},:;^|$~>()/\\[\\]])\\s*"), "$1");
// Remove comments
str = std::regex_replace(str, std::regex("/\\*.*?\\*/"), "");
// Remove unnecessary trailing semicolons
str = std::regex_replace(str, std::regex(":}"), "}");
// Shorten relative URIs
str = std::regex_replace(str, std::regex("[^\\.]\\./"), "");
// Add spacing around media ands
str = std::regex_replace(str, std::regex("(\\)?)\\s*and\\s*(\\(?)"), "$1 and $2");
return str;
}
int
main(void) {
std::string str, buffer;
while (std::getline(std::cin, buffer)) {
str += buffer;
}
std::cout << minify(str);
return 0;
}