libzypp 17.37.17
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>
19
20namespace ztui {
21
26inline 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 ) )
36
37 return zypp::str::printIndented( str, text, indent_r, width_r ); // even unindented as it also asserts a trailing '/n'
38}
39
41inline std::string printRichText( std::string text, unsigned indent_r = 0U, unsigned width_r = 0U )
42{
44 printRichText( s.stream(), std::move(text), indent_r, width_r );
45 return s.str();
46}
47
48}
49
50#endif
51
Regular expression.
Definition Regex.h:95
String related utilities and Regular expression matching.
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
std::string processRichText(const std::string &text)
Definition richtext.cc:205
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
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
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:213
std::string str() const
Definition String.h:223
const std::ostream & stream() const
Definition String.h:225