5 int WrapMode::wrap_pos(
const char *
str,
int wrapCol)
const {
13 if (!allowed_to_wrap())
throw_errorf(50,
"Oversized content - no wrapping allowed here (content='%s')", str);
17 const char *wrapAfter = get_seps();
20 for (; i >= 0 && !
occurs_in(str[i], wrapAfter); --i) {}
21 return i >= 0 ? i : wrapCol;
24 const char *WrapMode::print_return_wrapped(
Writer& write,
const char *
const content,
const int len,
const int rest_width)
const {
27 if (len<(rest_width+1)) {
32 int split_after = wrap_pos(content, rest_width);
35 if (
occurs_in(content[split_after],
" \n")) split_after--;
39 int continue_at = split_after+1;
40 while (continue_at < len &&
occurs_in(content[continue_at],
" \n")) continue_at++;
49 return content+continue_at;
52 void WrapMode::print(
Writer& write,
const char *first_prefix,
const char *other_prefix,
const char *content,
int max_width)
const {
55 int len = strlen(content)-1;
56 int prefix_len = strlen(first_prefix);
58 write.
out(first_prefix);
59 const char *rest = print_return_wrapped(write, content, len, max_width-prefix_len);
62 prefix_len = strlen(other_prefix);
68 write.
out(other_prefix);
69 rest = print_return_wrapped(write, content, len, max_width-prefix_len);
void throw_errorf(int error_num, const char *error_messagef,...) __ATTR__FORMAT(2) __ATTR__NORETURN
int fputs_len(const char *str, int len, Writer &write)
CONSTEXPR_INLINE bool has_content(const char *field)
void print(Writer &write, const char *first_prefix, const char *other_prefix, const char *content, int max_width) const
virtual void out(char ch)=0
bool occurs_in(char ch, const char *in)