diff options
-rw-r--r-- | tools.cpp | 12 | ||||
-rw-r--r-- | tools.h | 1 |
2 files changed, 13 insertions, 0 deletions
@@ -71,4 +71,16 @@ string StringRepeat(int times, const string& input) return result; } +string StringWordTruncated(const string& input, size_t maxLen, bool& truncated) +{ + if (input.length() <= maxLen) + { + return input; + } + truncated = true; + string result = input.substr(0, maxLen); + size_t pos = result.find_last_of(" \t,;:.\n?!'\"/\\()[]{}*+-"); + return result.substr(0, pos); +} + } // namespace vdrlive @@ -15,6 +15,7 @@ std::string StringReplace( std::string const& text, std::string const& substring std::vector< std::string > StringSplit( std::string const& text, char delimiter ); int StringToInt( std::string const& string, int base = 10 ); std::string StringRepeat(int times, const std::string& input); +std::string StringWordTruncated(const std::string& input, size_t maxLen, bool& truncated); struct bad_lexical_cast: std::runtime_error { |