-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_file.h
37 lines (30 loc) · 908 Bytes
/
html_file.h
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
#pragma once
#include "file.h"
#include "options.h"
#include <string>
#include <string_view>
#include <vector>
namespace html_file
{
inline std::string
read_file(const std::string &filename,
std::vector<std::pair<std::string_view, std::string_view>> additional_replacements = {})
{
auto file = file::read_file(filename);
auto find_and_replace = [&](std::string_view to_find, std::string_view replacement)
{
while (true)
{
auto index = file.find(to_find);
if (index == file.npos)
return;
file = file.replace(index, to_find.size(), replacement);
}
};
static std::string fullDomain = (global_options.use_tls ? "https://" : "http://") + global_options.domain;
find_and_replace("$$domain$$", fullDomain);
for (const auto &replacement : additional_replacements)
find_and_replace(replacement.first, replacement.second);
return file;
}
}