Commit fd1156a1 authored by Zhiping Jiang (蒋志平)'s avatar Zhiping Jiang (蒋志平) 💬

add space to newline translation

parent 38504df4
Pipeline #20981606 passed with stage
in 22 minutes and 49 seconds
......@@ -20,14 +20,48 @@ namespace EnhancedConsoleText {
void println(const std::string &content, FontEffect fontEffect, LineAlignment lineAlignment, FrontColor frontColor,
BackgroundColor bgColor) {
std::regex ws_re("\n");
std::regex newlineRegex("\n");
std::regex headingSpaceRegex("^\\s*");
std::regex tailingSpaceRegex("\\s*$");
std::smatch match;
auto headingNewlines = 0;
auto trailingNewlines = 0;
std::string spaceTrimedContent;
try {
if (std::regex_search(content, match, headingSpaceRegex)) {
auto headingSpaceStr = match.str();
headingNewlines = headingSpaceStr.size();
}
if (std::regex_search(content, match, tailingSpaceRegex) && match.size() > 0) {
auto trailingSpaceStr = match.str(0);
trailingNewlines = trailingSpaceStr.size();
}
spaceTrimedContent = std::regex_replace(content, headingSpaceRegex, "");
spaceTrimedContent = std::regex_replace(spaceTrimedContent, tailingSpaceRegex, "");
} catch (std::regex_error& e) {
// Syntax error in the regular expression
std::cout<<e.what()<<std::endl;
}
std::vector<std::string> lineSplits {
std::sregex_token_iterator(content.begin(), content.end(), ws_re, -1), {}
std::sregex_token_iterator(spaceTrimedContent.begin(), spaceTrimedContent.end(), newlineRegex, -1), {}
};
for(auto i = 0; i < headingNewlines; i ++)
std::cout<<std::endl;
for(auto i = 0; i < lineSplits.size(); i++) {
std::cout << decorateString(lineSplits[i], fontEffect, lineAlignment, frontColor, bgColor)<<std::endl;
}
for(auto i = 0; i < trailingNewlines; i ++)
std::cout<<std::endl;
}
void press2Continue(const std::string content) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment