-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.cpp
68 lines (64 loc) · 1.39 KB
/
record.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
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
63
64
65
66
67
68
#include <sstream>
#include "record.h"
#include "engine.h"
static std::string escape(const std::string &str)
{
std::ostringstream ret;
for (const char c : str) {
if (c == '<')
ret << "<";
else if (c == '>')
ret << ">";
else
ret << c;
}
return ret.str();
}
static std::string limit(std::string str, size_t size)
{
if (str.size() > size)
str.resize(size);
std::string::iterator i = str.begin();
while (true) {
std::string::iterator j = i;
for (int k = 0; k < 80; k++) {
if (*j == '\n')
k = 1;
if (j != str.end())
++j;
}
if (j == str.end())
break;
while (*j != ' ' && j != str.end())
j++;
if (j == str.end())
break;
*j = '\n';
i = ++j;
}
return str;
}
std::istream &operator >>(std::istream &stream, Record &record)
{
std::string meta, link;
std::getline(stream, meta);
std::getline(stream, link);
record.a_link = record.f_link = link;
/*
const std::string old = "pub/demo2023";
size_t i = record.a_link.find(old);
record.a_link.replace(i, old.size(), "Tribute");
*/
meta = escape(meta);
meta = limit(meta, 256);
std::istringstream I(meta);
I >> record.no;
std::getline(I, record.name, '(');
std::getline(I, record.group, ')');
return stream;
}
std::ostream &operator <<(std::ostream &stream, const Record &record)
{
#include "record.view"
return stream << record_view() << std::endl;
}