21 #include "../exception.h"
30 typedef std::map<std::string, std::vector<Listing::Block>>
Content;
38 const auto delim = line.find(
":");
39 if (delim != std::string::npos) {
41 while (i < line.size() && line[i] ==
' ')
43 currentChapter->back().mapping.emplace(line.substr(0, delim), line.substr(i));
50 const std::string originalLine = line;
57 if (line.back() ==
'\r')
61 auto numberSign = line.find(
'#');
62 if (numberSign != std::string::npos) {
64 for (
size_t i = 0; i < numberSign - 1; ++i)
69 line = line.substr(0, numberSign);
73 auto l = line.find_last_not_of(
' ');
74 if (l == std::string::npos)
76 if (l != line.length() - 1)
77 line = line.substr(0, l + 1);
84 if (line.front() !=
' ' && line.front() !=
'-' && line.back() ==
':') {
86 auto it =
chapters.emplace(std::piecewise_construct, std::forward_as_tuple(line), std::forward_as_tuple());
95 auto i = line.find_first_not_of(
' ');
96 if (i != std::string::npos && i + 2 < line.length() && line[i] ==
'-' && line[i + 1] ==
' ') {
112 else if (line.find_first_not_of(
' ') ==
chapterIndent.length()) {
124 static const int SIZE = 1024;
127 while (!stream.
eof()) {
128 std::memset(buffer, 0, SIZE);
129 stream(buffer, SIZE);
131 while (i < SIZE && buffer[i] != 0) {
132 if (buffer[i] ==
'\n') {
146 for (std::string line; std::getline(stream, line); )
155 str << (first ?
" - " :
" ") << it.first <<
": " << it.second << std::endl;
164 if (lineNumber > 0) {
186 str << it.first <<
":" << std::endl;
187 for (
auto& i : it.second)
202 chapters.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple());
std::map< std::string, std::string > mapping
void printOut(std::ostream &stream)
Prints out the block to an output stream.
std::string operator[](const std::string &key) const
Retrieves a value by key.
const std::vector< Block > & operator[](const std::string &key) const
Retrieves a chapter in the listing by its name.
bool has(const std::string &key) const
Returns true if a specific chapter is present in the listing.
void printOut(std::ostream &stream)
Prints out the listing to an output stream.
std::map< std::string, std::vector< Block > > chapters
void emplace(const std::string &key, Block &&block)
Adds a block to a chapter.
std::vector< Listing::Block > * currentChapter
void processLine(std::string line)
Parser(InputStream &stream, Content &chapters)
void extractKeyValuePair(std::string line)
std::string chapterIndent
std::map< std::string, std::vector< Listing::Block > > Content
Parser(std::istream &stream, Content &chapters)
std::string to_string(Beatmup::NNets::ActivationFunction function)
Beatmup::AffineMapping & mapping
JNIEnv jobject jstring str