15#ifndef ZYPP_UTILS_TEXT_H_ 
   16#define ZYPP_UTILS_TEXT_H_ 
   21#include <boost/utility/string_ref.hpp> 
   22#include <zypp-core/base/DtorReset> 
   30#define ZYPPER_TRACE_MBS 0 
   34    static const char _oooooooo = 
static_cast<char>(0000);
 
   35    static const char _Xooooooo = 
static_cast<char>(0200);
 
   36    static const char _XXoooooo = 
static_cast<char>(0300);
 
   37    static const char _XXXooooo = 
static_cast<char>(0340);
 
   38    static const char _XXXXoooo = 
static_cast<char>(0360);
 
   39    static const char _XXXXXooo = 
static_cast<char>(0370);
 
   40    static const char _ooXXXXXX = 
static_cast<char>(0077);
 
 
  105      if ( 
_cols == 
size_t(-1) )
 
  112          if ( 
_cols == 
size_t(-1) )
 
 
  144        if ( 
_tread >= (
size_t)-2 )
 
  167            if ( ::iswspace(
_wc) )
 
  178            else if ( 
_wc == L
'\033' )       
 
  181              if ( asize && asize <= 
_trest )
 
 
  194      const char * p = pos_r;
 
  195      if ( *p == 
'\033' && *(++p) == 
'[' )
 
  197        for ( 
char ch = *(++p); ( 
'0' <= ch && ch <= 
'9' ) || ch ==
';'; ch = *(++p) )
 
 
 
  312#if ( ZYPPER_TRACE_MBS) 
  313      _out << 
"<NL>" << std::endl;  
 
 
  332#if ( ZYPPER_TRACE_MBS ) 
  334          _out << 
"<BR>" << std::endl;      
 
  336        _out << std::string( count_r, 
'\n' );
 
 
  366    void startPar( boost::string_ref text_r, 
size_t increment_r )
 
 
  376    void addString( boost::string_ref text_r, 
size_t increment_r )
 
 
  387    void writeText( boost::string_ref text_r, 
size_t increment_r )
 
 
  399    void writePar( boost::string_ref text_r, 
size_t increment_r )
 
 
  407    void writeDefinition( boost::string_ref tag_r, boost::string_ref text_r, 
size_t tagincr_r, 
size_t textincr_r )
 
  412        write( tag_r, 
false );
 
 
  428    void writeDefinition( boost::string_ref tag_r, boost::string_ref text_r, 
size_t tagincr_r, 
size_t textincr_r, 
size_t increment_r )
 
 
  431    void writeDefinition( boost::string_ref tag_r, boost::string_ref text_r, 
size_t increment_r )
 
 
  439    void write( boost::string_ref text_r, 
bool leadingWSindents_r = 
true )
 
  447        else if ( it.isWS() )
 
 
  519        _out << std::string( useIndent, 
' ' ) <<  boost::string_ref( 
_word, 
_wSize );
 
  529          _out << std::string( useIndent, 
' ' );
 
 
  543    static size_t fixIndent( 
size_t indent_r, 
int indentFix_r )
 
  547        if ( indentFix_r < 0 && ( 
size_t(-indentFix_r) >= indent_r ) )
 
  550          indent_r += indentFix_r;
 
 
  569      increment_r += current_r;
 
  570      if ( wrap_r && current_r < wrap_r )
 
  572        size_t limit = current_r + ( (wrap_r-current_r)/2 );
 
  573        if ( limit < increment_r )
 
 
 
  614#undef ZYPPER_TRACE_MBS 
 
  631inline void mbs_write_wrapped( std::ostream & 
out, boost::string_ref text_r, 
size_t indent_r, 
size_t wrap_r, 
int indentFix_r = 0 )
 
 
  655std::string 
mbs_substr_by_width( boost::string_ref text_r, std::string::size_type colpos_r = 0, std::string::size_type collen_r = std::string::npos );
 
Assign a vaiable a certain value when going out of scope.
size_t mbs_width(boost::string_ref text_r)
Returns the column width of a multi-byte character string text_r.
std::string mbs_substr_by_width(boost::string_ref text_r, std::string::size_type colpos_r, std::string::size_type collen_r)
Returns a substring of a multi-byte character string text_r starting at screen column cpos_r and bein...
void mbs_write_wrapped(std::ostream &out, boost::string_ref text_r, size_t indent_r, size_t wrap_r, int indentFix_r=0)
Wrap and indent given text and write it to the output stream out.
static const char _XXoooooo
static const char _oooooooo
static const char _XXXXoooo
static const char _XXXXXooo
static const char _Xooooooo
static const char _XXXooooo
static const char _ooXXXXXX
MbsIteratorNoSGR & operator++()
MbsIteratorNoSGR(boost::string_ref text_r)
Iterate chars and ANSI SGR in a multi-byte character string.
MbsIterator(boost::string_ref text_r)
const wchar_t & operator*() const
wchar_t & operator*()
Use with care; all WS are faked to either ' ' or ' '.
unsigned ansiSize(const char *pos_r)
boost::string_ref ref() const
MbsIterator & operator++()
Temporarily increase indent.
ScopedIndentIncrement(MbsWriteWrapped &mww_r, size_t increment_r)
Write MBString optionally wrapped and indented.
void gotoParBegin()
Open a new paragraph if not atParBegin.
void startPar(boost::string_ref text_r)
Write text_r; starting a new paragraph.
void gotoNextLine(size_t count_r=1)
Add count_r (1) new lines in this par (BR unconditionally)
MbsWriteWrapped(std::ostream &out, size_t wrap_r)
void writeText(boost::string_ref text_r)
Continue writing text (separated by WS if not atLineBegin).
void writeDefinition(boost::string_ref tag_r, boost::string_ref text_r, size_t tagincr_r, size_t textincr_r, size_t increment_r)
void resetToParBegin()
Reset housekeeping data to the beginning of a paragraph (does not write anything)
void gotoLineBegin()
Open a new line in this paragraph if not atLineBegin.
const size_t _defaultWrap
void writeDefinition(boost::string_ref tag_r, boost::string_ref text_r)
void startPar(boost::string_ref text_r, size_t increment_r)
void writeText(boost::string_ref text_r, size_t increment_r)
int defaultIndentFix() const
void writeout(bool force_r=false)
Write any pending "indent/gap+word" and reset for next word.
MbsWriteWrapped(std::ostream &out, size_t indent_r, size_t wrap_r, int indentFix_r=0)
MbsWriteWrapped(std::ostream &out)
void writePar(boost::string_ref text_r)
Write text_r; starting a new paragraph and ending it after the text was written.
void writeDefinition(boost::string_ref tag_r, boost::string_ref text_r, size_t increment_r)
size_t fixIndent(size_t indent_r)
Return fixed indent_r (unsets _indentFix)
size_t defaultIndent() const
size_t defaultWrap() const
const int _defaultIndentFix
void write(boost::string_ref text_r, bool leadingWSindents_r=true)
Append text_r indented and wrapped at the current position.
static size_t fixIndent(size_t indent_r, int indentFix_r)
Return fixed indent_r.
void writePar(boost::string_ref text_r, size_t increment_r)
void clearGap()
Set no gaps.
void addString(boost::string_ref text_r)
Continue writing text at the current position.
const size_t _defaultIndent
ScopedIndentIncrement scopedIndentIncrement(size_t increment_r)
Temporarily increase indent.
static size_t saneIncrementIndent(size_t current_r, size_t increment_r, size_t wrap_r)
Return incremented indent, but not to more than 50% of the remaining line size if wrapped.
size_t saneIncrementIndent(size_t increment_r)
Return incremented _indent, but not more than 50% of the remaining line size if wrapped.
void writeDefinition(boost::string_ref tag_r, boost::string_ref text_r, size_t tagincr_r, size_t textincr_r)
Write a tag_r with indented definition text_r.
void clearIndent()
Set default indent at par start (reloads _indentFix)
void addString(boost::string_ref text_r, size_t increment_r)
void gotoNextPar()
Write out any pending word and start a new par (NL unconditionally)
void clearWord()
Set no word pending.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...