string("-") + resit->second->edition().asString() :
string())
<< " ";
- wrap_text(out, s.str(), 2, _wrap_width);
+ mbs_write_wrapped(out, s.str(), 2, _wrap_width);
out << endl;
return;
}
s << format(_("After the operation, %s will be freed.")) % abs.asString(0,1,1);
}
- wrap_text(out, s.str(), 0, _wrap_width);
+ mbs_write_wrapped(out, s.str(), 0, _wrap_width);
out << endl;
}
gotcha = true;
}
s << "." << endl;
- wrap_text(out, s.str(), 0, _wrap_width);
+ mbs_write_wrapped(out, s.str(), 0, _wrap_width);
}
// --------------------------------------------------------------------------
// stream.width (widths[c]); // that does not work with multibyte chars
const string & s = *i;
- ssize = string_to_columns (s);
+ ssize = mbs_width (s);
if (ssize > parent._max_width[c])
stream << (s.substr(0, parent._max_width[c] - 2) + "->"); //! \todo FIXME cut at the correct place
else
}
unsigned &max = _max_width[c];
- unsigned cur = string_to_columns (*i);
+ unsigned cur = mbs_width (*i);
if (max < cur)
max = cur;
|__/|_| |_|
\*---------------------------------------------------------------------------*/
-#include <wchar.h>
+#include <cwchar>
#include <cstring>
-#include <sstream>
+#include <ostream>
#include "utils/text.h"
// return the number of columns in str, or -1 if there's an error
static
-int string_to_columns_e (const string & str)
+int mbs_width_e (const string & str)
{
// from smpppd.src.rpm/format.cc, thanks arvin
return s_cols;
}
-unsigned string_to_columns (const string& str)
+unsigned mbs_width (const string& str)
{
- int c = string_to_columns_e (str);
+ int c = mbs_width_e(str);
if (c < 0)
return str.length(); // fallback if there was an error
else
}
-void wrap_text(ostream & out, const string & text,
+void mbs_write_wrapped(ostream & out, const string & text,
unsigned indent, unsigned wrap_width, int initial)
{
const char * s = text.c_str();
#include <string>
#include <iosfwd>
-/** Returns the length of the string in columns */
-/*
+/** Returns the column width of a multi-byte character string \a str */
+unsigned mbs_width (const std::string & str);
+
+/**
+ * Wrap and indent given \a text and write it to the output stream \a out.
+ *
* TODO
* - delete whitespace at the end of lines
* - keep one-letter words with the next
+ *
+ * \param out output stream to write to
+ * \param test text to wrap
+ * \param indent number of columns by which to indent the whole text
+ * \param wrap_width number of columns the text should be wrapped into
+ * \param initial number of columns by which the first line should be indented
+ * by default, the first line is indented by \a indent
+ *
*/
-unsigned string_to_columns (const std::string & str);
-
-void wrap_text(std::ostream & out, const std::string & text,
+void mbs_write_wrapped (
+ std::ostream & out,
+ const std::string & text,
unsigned indent, unsigned wrap_width, int initial = -1);
#endif /* ZYPPER_UTILS_TEXT_H_ */