btool
A parser/converter/transpiler for .bib files
PlainTextGenerator.cpp
Go to the documentation of this file.
1 #include <PlainTextGenerator.hpp>
2 #include <string>
3 
9 auto PlainTextGenerator::write() -> std::string {
10  if (elements.empty()) fail("Cannot output empty results.", "");
11  std::string result;
12  for (const auto &element : elements){
13  std::string repr = "@" + element.style + "{" + element.id + ",\n";
14  for (const auto &key : sortedFields(element.attributes)){
15  repr += "\t" + key.name + " = " + key.value + ",\n";
16  }
17  repr += "}\n";
18  result += repr;
19  }
20  return result;
21 }
22 
27 auto PlainTextGenerator::fail(const std::string &message, const std::string &type) -> void {
28  AbstractGenerator::fail(message, "plain-text");
29 }
30 
31 PlainTextGenerator::PlainTextGenerator(const std::vector<BibElement> &elements) : AbstractGenerator{elements} {};
AbstractGenerator
Definition: AbstractGenerator.hpp:14
PlainTextGenerator.hpp
AbstractGenerator::fail
virtual auto fail(const std::string &message, const std::string &type="unknown") -> void
Definition: AbstractGenerator.cpp:12
PlainTextGenerator::fail
auto fail(const std::string &message, const std::string &type) -> void override
Definition: PlainTextGenerator.cpp:27
PlainTextGenerator::PlainTextGenerator
PlainTextGenerator(const std::vector< BibElement > &elements)
Definition: PlainTextGenerator.cpp:31
PlainTextGenerator::write
auto write() -> std::string override
Definition: PlainTextGenerator.cpp:9
AbstractGenerator::elements
std::vector< BibElement > elements
Elements to write.
Definition: AbstractGenerator.hpp:16