24 #include "ppl-config.h"
26 #include "assertions.hh"
31 namespace IO_Operators {
35 const unsigned indent_depth,
36 const unsigned preferred_first_line_length,
37 const unsigned preferred_line_length) {
39 std::string dst_string;
40 const char *src = src_string.c_str();
41 for (
unsigned line = 0; ; ++line) {
42 const unsigned line_length = ((line == 0)
43 ? preferred_first_line_length
44 : preferred_line_length);
45 unsigned last_comma = npos;
46 unsigned last_space = npos;
47 unsigned split_pos = npos;
49 for (idx = 0; idx <= line_length; ++idx) {
50 if (src[idx] ==
'\0' || src[idx] ==
'\n') {
54 if (src[idx] ==
',' && idx < line_length) {
61 if (split_pos == npos) {
62 if (last_comma != npos) {
63 split_pos = last_comma + 1;
65 else if (last_space != npos) {
66 split_pos = last_space;
69 for ( ; src[idx] !=
'\0'; ++idx) {
70 if (src[idx] ==
',') {
81 PPL_ASSERT(split_pos != npos);
82 if (split_pos > 0 && line > 0 && indent_depth > 0) {
83 dst_string.append(indent_depth,
' ');
85 dst_string.append(src, split_pos);
96 dst_string.push_back(
'\n');
bool is_space(char c)
Returns true if c is any kind of space character.
std::string wrap_string(const std::string &src_string, const unsigned indent_depth, const unsigned preferred_first_line_length, const unsigned preferred_line_length)
Utility function for the wrapping of lines of text.
The entire library is confined to this namespace.