Remove unused + cosnt and so on
This commit is contained in:
parent
c09929d2f7
commit
28613af006
21
src/Page.cpp
21
src/Page.cpp
@ -19,45 +19,44 @@
|
|||||||
#include "libxml/xpath.h"
|
#include "libxml/xpath.h"
|
||||||
|
|
||||||
|
|
||||||
bool is_number(std::string_view s){
|
bool is_number(const std::string_view s) {
|
||||||
return std::all_of(s.begin(), s.end(), [](unsigned char c ){
|
return std::ranges::all_of(s, [](const unsigned char c) {
|
||||||
return std::isdigit(c);
|
return std::isdigit(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void italize_numbers(std::string &content, size_t leave_chars = 0) {
|
void italize_numbers(std::string &content, size_t leave_chars = 0) {
|
||||||
size_t end = content.size();
|
size_t end = content.size();
|
||||||
|
|
||||||
// Process backwards, word by word
|
// Process backwards, word by word
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t space = content.rfind(' ', end - 1);
|
const size_t space = content.rfind(' ', end - 1);
|
||||||
size_t begin = (space == std::string::npos) ? 0 : space + 1;
|
const size_t begin = (space == std::string::npos) ? 0 : space + 1;
|
||||||
size_t word_length = end - begin;
|
const size_t word_length = end - begin;
|
||||||
|
|
||||||
if (is_number(content.substr(begin, word_length))) {
|
if (is_number(content.substr(begin, word_length))) {
|
||||||
content.insert(end, ansi::CLEAR);
|
content.insert(end, ansi::CLEAR);
|
||||||
content.insert(begin, ansi::ITALIC);
|
content.insert(begin, ansi::ITALIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (space == std::string::npos)
|
if (space == std::string::npos)
|
||||||
break;
|
break;
|
||||||
if (leave_chars >= space)
|
if (leave_chars >= space)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
end = space;
|
end = space;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pretty_format_page(std::string &content) {
|
void pretty_format_page(std::string &content) {
|
||||||
content.insert(0, ansi::BOLD);
|
content.insert(0, ansi::BOLD);
|
||||||
size_t line_end = content.find("\n");
|
const size_t line_end = content.find("\n");
|
||||||
content.insert(line_end, ansi::CLEAR);
|
content.insert(line_end, ansi::CLEAR);
|
||||||
|
|
||||||
italize_numbers(content, line_end + ansi::CLEAR.size());
|
italize_numbers(content, line_end + ansi::CLEAR.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Page::Page(const uint_fast8_t number): m_number(number), m_subpage(fetchSubpage()) {
|
Page::Page(const uint_fast8_t number): m_number(number), m_subpage(fetchSubpage()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ static constexpr uint_fast8_t MAX_WHITESPACE = 2;
|
|||||||
class Page
|
class Page
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint_fast8_t m_number{};
|
uint_fast8_t m_number;
|
||||||
std::string m_subpage;
|
std::string m_subpage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
Page &operator-=(int);
|
Page &operator-=(int);
|
||||||
|
|
||||||
std::string str() const;
|
[[nodiscard]] std::string str() const;
|
||||||
|
|
||||||
bool refresh();
|
bool refresh();
|
||||||
|
|
||||||
@ -40,6 +40,4 @@ private:
|
|||||||
[[nodiscard]] std::string url() const;
|
[[nodiscard]] std::string url() const;
|
||||||
|
|
||||||
[[nodiscard]] std::string fetchSubpage() const;
|
[[nodiscard]] std::string fetchSubpage() const;
|
||||||
|
|
||||||
[[nodiscard]] bool contentEquals(const std::vector<std::string> &subpagesOther) const;
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user