mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-24 07:27:44 +01:00
[Summary] Added function for splitting long std::string on substring separated by "\n"
[Reviewed] YPozdnyakov
This commit is contained in:
parent
3757a5239d
commit
e2709e8a40
2 changed files with 30 additions and 0 deletions
|
|
@ -1038,3 +1038,32 @@ ARDOUR_UI_UTILS::track_number_to_string (
|
|||
rv += Glib::Markup::escape_text(postfix);
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::string
|
||||
ARDOUR_UI_UTILS::split_on_lines (std::string message, size_t n_characters_in_line)
|
||||
{
|
||||
if (message.size()<n_characters_in_line)
|
||||
return message;
|
||||
|
||||
std::string splited_message = "";
|
||||
|
||||
std::vector<std::string> words;
|
||||
boost::split (words, message, boost::is_any_of(" "));
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
while( i < words.size() ) {
|
||||
|
||||
std::string new_line = words[i++];
|
||||
|
||||
// Create next line
|
||||
while ( (i < words.size()) && (new_line.size() + words[i].size() < n_characters_in_line) )
|
||||
new_line += " " + words[i++];
|
||||
|
||||
if ( splited_message.size() > 0 ) // not first line
|
||||
splited_message += "\n";
|
||||
splited_message += new_line;
|
||||
}
|
||||
|
||||
return splited_message;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ std::string rate_as_string (float r);
|
|||
ARDOUR::framecnt_t string_as_rate (const std::string& string_sr);
|
||||
|
||||
std::string track_number_to_string (int64_t tracknumber, std::string sep = "", std::string postfix = "");
|
||||
std::string split_on_lines (std::string message, size_t n_characters_in_line);
|
||||
|
||||
} // namespace
|
||||
#endif /* __ardour_gtk_utils_h__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue