size_t ReplaceSubstr(Wtroka& str, const TWtringBuf& from, const TWtringBuf& to) { size_t count = 0; size_t pos = str.off(TCharTraits<wchar16>::Find(~str, +str, ~from, +from)); while (pos != Wtroka::npos) { str.replace(pos, +from, ~to, 0, Wtroka::npos, +to); ++count; size_t next = pos + to.size(); pos = str.off(TCharTraits<wchar16>::Find(~str + next, +str - next, ~from, +from)); } return count; }
void Collapse(Wtroka& w) { size_t len = w.size(); for (size_t start = 0; start < len; ++start) { size_t n = 0; for (; start + n < len; ++n) { if (!IsWhitespace(w[start + n])) break; } if (n > 1 || (n == 1 && w[start] != ' ')) { w.replace(start, n, 1, ' '); len = w.size(); } } }