From c192f352f004c3a24a8012c8fdc9ce83d7fbd15a Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 14 Jan 2020 22:28:14 +0100 Subject: Extract post formats via regex. --- src/instance.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/instance.cpp b/src/instance.cpp index ac2f308..fb8db81 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -121,23 +121,23 @@ vector Instance::get_post_formats() noexcept return _post_formats; } - constexpr string_view searchstring{R"("postFormats":[)"}; - auto pos{answer.body.find(searchstring)}; - if (pos == string::npos) + const regex re_allformats(R"("postFormats"\s*:\s*\[([^\]]+)\])"); + smatch match; + if (!regex_search(answer.body, match, re_allformats)) { debuglog << "Couldn't find metadata.postFormats.\n"; _post_formats = {default_value}; return _post_formats; } - pos += searchstring.size(); - auto endpos{answer.body.find("],", pos)}; - string formats{answer.body.substr(pos, endpos - pos)}; - debuglog << "Extracted postFormats: " << formats << '\n'; + string allformats{match[1].str()}; + debuglog << "Found postFormats: " << allformats << '\n'; + + const regex re_format(R"(\s*"([^"]+)\"\s*,?)"); - while ((pos = formats.find('"', 1)) != string::npos) + while (regex_search(allformats, match, re_format)) { - _post_formats.push_back(formats.substr(1, pos - 1)); - formats.erase(0, pos + 2); // 2 is the length of: ", + _post_formats.push_back(match[1].str()); + allformats = match.suffix(); debuglog << "Found postFormat: " << _post_formats.back() << '\n'; } } -- cgit v1.2.3-54-g00ecf rel='nofollow'>commitdiffstats
path: root/examples/example02_streaming.cpp
blob: 0f95343d335c060646853df3aa0cabbd5e9607f6 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102