14 const std::string &text,
18 std::vector<std::string> tokens;
19 boost::algorithm::split(tokens, text, boost::algorithm::is_space());
23 while (text[length] ==
' ') {
27 for (
int i = 0; i < static_cast<int>(tokens.size()) - 1; i++) {
28 length +=
static_cast<int>(tokens[i].length());
30 if (length +
static_cast<int>(tokens[i + 1].length()) + 1 > linewidth) {
32 for (
int ws = 0; ws < indentation; ws++) {
41 wrapped += tokens.back();
68 std::string converted(wstr.length(),
'\0');
70 std::string mb(MB_CUR_MAX,
'\0');
71 for (
size_t i = 0; i != wstr.length(); ++i) {
73 std::size_t ret = std::wctomb(&mb[0], wstr[i]);
74 converted[i] = (ret == 1) ? mb.front() : fill;
81 const std::size_t len1 = s1.size(), len2 = s2.size();
82 using Matrix = Eigen::Matrix<std::size_t, Eigen::Dynamic, Eigen::Dynamic>;
83 Matrix distances(len1 + 1, len2 + 1);
86 for (std::size_t i = 1; i <= len1; ++i)
88 for (std::size_t i = 1; i <= len2; ++i)
91 for (std::size_t i = 1; i <= len1; ++i) {
92 for (std::size_t j = 1; j <= len2; ++j) {
93 auto deletionCost = distances(i - 1, j) + 1;
94 auto insertionCost = distances(i, j - 1) + 1;
95 auto substitutionCost = distances(i - 1, j - 1) + (s1[i - 1] == s2[j - 1] ? 0 : 1);
96 distances(i, j) = std::min({deletionCost, insertionCost, substitutionCost});
100 return distances(len1, len2);