libzypp  17.35.19
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 {
44  printRichText( s.stream(), std::move(text), indent_r, width_r );
45  return s.str();
46 }
47 
48 }
49 
50 #endif
51 
std::string str() const
Definition: String.h:222
Regular expression.
Definition: Regex.h:94
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
const std::ostream & stream() const
Definition: String.h:224
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:845
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition: String.h:211
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
Definition: Regex.h:70
std::string processRichText(const std::string &text)
Definition: richtext.cc:205