-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdvanced.cpp
More file actions
99 lines (82 loc) · 3.19 KB
/
Copy pathAdvanced.cpp
File metadata and controls
99 lines (82 loc) · 3.19 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
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
// This was generated by an LLM unlike the rest of these examples.
#ifndef LIPSUM_BUILD_STATIC
# define LIPSUM_IMPLEMENTATION // only for header-only usage
#endif
#include <lipsum.hpp>
// A small helper to replace all occurrences of a token in a string.
static std::string
ReplaceAll(std::string& s, const std::string& from, const std::string& to)
{
if (from.empty())
return s;
size_t pos = 0;
while ((pos = s.find(from, pos)) != std::string::npos)
{
s.replace(pos, from.length(), to);
pos += to.length();
}
return s;
}
int main()
{
std::cout << "Notice: this example was AI-generated.\n";
// Use the object-oriented generator.
lpsm::Generator gen;
gen.change_setting("wordFmt", 3, 6);
gen.change_setting("wordURL", 2, 4);
gen.change_setting("word", 4, 8);
gen.change_setting("frag", 1, 2);
// Build a template Markdown document with tokens to fill.
std::string mdTemplate =
"{TITLE}\n\n"
"## About\n\n"
"{ABOUT}\n\n"
"## Highlights\n\n"
"{HIGHLIGHTS}\n\n"
"## Quick Example\n\n"
"```cpp\n"
"// This is a tiny snippet; it's intentionally silly\n"
"auto awesome = \"{WORD}\";\n"
"std::cout << \"Behold: \" << awesome << std::endl;\n"
"```\n\n"
"## Related Link\n\n"
"{MDLINK}\n\n"
"## Gallery\n\n"
"{GALLERY}\n";
// Fill tokens using the library:
std::string title = gen.fmt_header(1, lpsm::MARKDOWN); // short title
// About: a short Markdown paragraph (use Markdown generator to add some
// formatting)
std::string about = gen.fmt_paragraph(1, lpsm::USELIPSUM, lpsm::MARKDOWN);
// Highlights: a markdown list (unordered)
std::string highlights = gen.fmt_list(lpsm::UNORDERED, lpsm::MARKDOWN);
// A single random word used in the code block
std::string word = gen.word();
// A markdown link
std::string mdLink = gen.fmt_link(lpsm::MARKDOWN);
// Gallery: several short paragraphs
std::string gallery = gen.paragraph(3, lpsm::NO_USELIPSUM);
gen.change_setting("word", 2, 4);
gen.change_setting("frag", 1, 1);
// Do a few playful replacements in the gallery to mimic captions
std::string caption = std::string("> Caption: ") + gen.sentence() + "\n\n";
gallery = caption + gallery;
// Now replace tokens in template
std::string md = mdTemplate;
md = ReplaceAll(md, "{TITLE}", title);
md = ReplaceAll(md, "{ABOUT}", about);
md = ReplaceAll(md, "{HIGHLIGHTS}", highlights);
md = ReplaceAll(md, "{WORD}", word);
md = ReplaceAll(md, "{MDLINK}", mdLink);
md = ReplaceAll(md, "{GALLERY}", gallery);
// Print the generated Markdown document
std::cout << "----- Generated Markdown -----\n\n";
std::cout << md << "\n";
// Show some simple statistics
int sentences = lpsm::CountSentences(md);
int words = lpsm::CountWords(md);
std::cout << "----- Stats -----\n";
std::cout << "Sentences: " << sentences << "\n";
std::cout << "Words: " << words << "\n";
return 0;
}