std::vector<std::unique_ptr<InfoBoxLine> > InfoBoxLine::split(const std::string& text, float width) { std::vector<std::unique_ptr<InfoBoxLine> > lines; std::string::size_type i = 0; std::string::size_type l; char format_char = '#'; while(i < text.size()) { // take care of empty lines - represent them as blank lines of normal text if (text[i] == '\n') { lines.emplace_back(new InfoBoxLine('\t', "")); i++; continue; } // extract the format_char format_char = text[i]; i++; if (i >= text.size()) break; // extract one line l = text.find("\n", i); if (l == std::string::npos) l=text.size(); std::string s = text.substr(i, l-i); i = l+1; // if we are dealing with an image, just store the line if (format_char == '!') { lines.emplace_back(new InfoBoxLine(format_char, s)); continue; } // append wrapped parts of line into list std::string overflow; do { FontPtr font = get_font_by_format_char(format_char); std::string s2 = s; if (font) s2 = font->wrap_to_width(s2, width, &overflow); lines.emplace_back(new InfoBoxLine(format_char, s2)); s = overflow; } while (s.length() > 0); } return lines; }