strip.cpp 499 B

12345678910111213141516171819
  1. #include "strip.h"
  2. #include "ascii.h"
  3. #include <util/string/reverse.h>
  4. void CollapseText(const TString& from, TString& to, size_t maxLen) {
  5. Collapse(from, to, maxLen);
  6. StripInPlace(to);
  7. if (to.size() >= maxLen) {
  8. to.remove(maxLen - 5); // " ..."
  9. ReverseInPlace(to);
  10. size_t pos = to.find_first_of(" .,;");
  11. if (pos != TString::npos && pos < 32) {
  12. to.remove(0, pos + 1);
  13. }
  14. ReverseInPlace(to);
  15. to.append(" ...");
  16. }
  17. }