-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommon.cpp
More file actions
62 lines (48 loc) · 1.62 KB
/
Copy pathcommon.cpp
File metadata and controls
62 lines (48 loc) · 1.62 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <odr/internal/html/common.hpp>
#include <odr/internal/abstract/file.hpp>
#include <odr/internal/crypto/crypto_util.hpp>
#include <odr/internal/util/stream_util.hpp>
#include <odr/internal/util/string_util.hpp>
#include <odr/html.hpp>
#include <odr/style.hpp>
#include <fstream>
#include <iomanip>
#include <sstream>
namespace odr::internal {
std::string html::escape_text(std::string text) {
if (text.empty()) {
return text;
}
util::string::replace_all(text, "&", "&");
util::string::replace_all(text, "<", "<");
util::string::replace_all(text, ">", ">");
if (text.front() == ' ') {
text = " " + text.substr(1);
}
if (text.back() == ' ') {
text = text.substr(0, text.length() - 1) + " ";
}
util::string::replace_all(text, " ", " ");
// TODO ` ` is not a tab
util::string::replace_all(text, "\t", " ");
return text;
}
std::string html::color(const Color &color) {
std::stringstream ss;
ss << "#";
ss << std::setw(6) << std::setfill('0') << std::hex << color.rgb();
return ss.str();
}
std::string html::file_to_url(const std::string &file,
const std::string &mime_type) {
return "data:" + mime_type + ";base64," + crypto::util::base64_encode(file);
}
std::string html::file_to_url(std::istream &file,
const std::string &mime_type) {
return file_to_url(util::stream::read(file), mime_type);
}
std::string html::file_to_url(const abstract::File &file,
const std::string &mime_type) {
return file_to_url(*file.stream(), mime_type);
}
} // namespace odr::internal