DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
plain_text_exporter.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_PLAIN_TEXT_EXPORTER_H
13 #define DOCWIRE_PLAIN_TEXT_EXPORTER_H
14 
15 #include "chain_element.h"
16 #include "document_elements.h"
17 
18 namespace docwire
19 {
20 
21 struct eol_sequence { std::string v; };
22 
24 {
25  std::function<std::string(const document::link&)> format_opening;
26  std::function<std::string(const document::close_link&)> format_closing;
27 };
28 
32 class DOCWIRE_CORE_EXPORT plain_text_exporter: public chain_element, public with_pimpl<plain_text_exporter>
33 {
34 public:
35  plain_text_exporter(eol_sequence eol = eol_sequence{"\n"}, link_formatter formatter = default_link_formatter);
36 
37  virtual continuation operator()(message_ptr msg, const message_callbacks& emit_message) override;
38 
39  bool is_leaf() const override
40  {
41  return false;
42  }
43 
44 private:
45  inline static const link_formatter default_link_formatter =
46  {
47  .format_opening = [](const document::link& link)
48  {
49  return link.url ? "<" + *link.url + ">" : "";
50  },
51  .format_closing = [](const document::close_link&)
52  {
53  return "";
54  }
55  };
56 
57  using with_pimpl<plain_text_exporter>::impl;
58 };
59 
60 } // namespace docwire
61 
62 #endif //DOCWIRE_PLAIN_TEXT_EXPORTER_H
Exports data to plain text format.
bool is_leaf() const override
Check if chain element is a leaf (last element which doesn't produce any messages)....
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19