12 #ifndef MLPACK_CORE_UTIL_HYPHENATE_STRING_HPP 13 #define MLPACK_CORE_UTIL_HYPHENATE_STRING_HPP 28 const std::string& prefix,
29 const bool force =
false)
31 if (prefix.size() >= 80)
33 throw std::invalid_argument(
"Prefix size must be less than 80");
36 size_t margin = 80 - prefix.size();
37 if (str.length() < margin && !force)
42 while (pos < str.length())
46 splitpos = str.find(
'\n', pos);
47 if (splitpos == std::string::npos || splitpos > (pos + margin))
50 if (str.length() - pos < margin)
52 splitpos = str.length();
56 splitpos = str.rfind(
' ', margin + pos);
57 if (splitpos <= pos || splitpos == std::string::npos)
58 splitpos = pos + margin;
61 out += str.substr(pos, (splitpos - pos));
62 if (splitpos < str.length())
69 if (str[pos] ==
' ' || str[pos] ==
'\n')
Linear algebra utility functions, generally performed on matrices or vectors.
std::string HyphenateString(const std::string &str, const std::string &prefix, const bool force=false)
Hyphenate a string or split it onto multiple 80-character lines, with some amount of padding on each ...