libzypp 17.37.10

richtext.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* Strictly for internal use!
12*/
13#ifndef ZYPP_TUI_UTILS_RICHTEXT_H_
14#define ZYPP_TUI_UTILS_RICHTEXT_H_
15
16#include <iosfwd>
17#include <zypp-core/base/String.h>
18#include <zypp-core/base/Regex.h>
19
20 namespace ztui {
21
26 inline std::ostream & printRichText( std::ostream & str, std::string text, unsigned indent_r = 0U, unsigned width_r = 0U )
27{
28 std::string processRichText( const std::string& text );
29
30 if ( text.empty() )
31 return str;
32
33 static const zypp::str::regex rttag("^[ \t\r\n]*<(p|!--[- ]*DT:Rich[ -]*--)>");
34 if( zypp::str::regex_match( text, rttag ) )
35 text = processRichText( text );
36
37 return zypp::str::printIndented( str, text, indent_r, width_r ); // even unindented as it also asserts a trailing '/n'
38}
39
41 inline std::string printRichText( std::string text, unsigned indent_r = 0U, unsigned width_r = 0U )
42{
43 zypp::str::Str s;
44 printRichText( s.stream(), std::move(text), indent_r, width_r );
45 return s.str();
46}
47
48}
49
50#endif
51
zypp::str::regex
Regular expression.
Definition Regex.h:95
str
String related utilities and Regular expression matching.
ztui::text
Definition Out.cc:24
ztui
Definition application.cc:13
ztui::printRichText
std::ostream & printRichText(std::ostream &str, std::string text, unsigned indent_r=0U, unsigned width_r=0U)
Print [Rich]Text optionally indented.
Definition richtext.h:26
ztui::processRichText
std::string processRichText(const std::string &text)
Definition richtext.cc:205
zypp::str::regex_match
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
Definition Regex.h:70
zypp::str::printIndented
std::ostream & printIndented(std::ostream &str, const std::string &text_r, const std::string &indent_r=" ", unsigned maxWitdh_r=0)
Indent by string [" "] optionally wrap.
Definition String.h:915
zypp::str::Str
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:213
zypp::str::Str::str
std::string str() const
Definition String.h:223
zypp::str::Str::stream
const std::ostream & stream() const
Definition String.h:225
Regex.h
String.h