From 862f706301ab6d758af14d7342ae0499cfe3b5ad Mon Sep 17 00:00:00 2001 From: Dieter Hametner Date: Mon, 8 Jan 2007 00:54:24 +0000 Subject: New function StringWordTruncate added --- tools.cpp | 12 ++++++++++++ tools.h | 1 + 2 files changed, 13 insertions(+) diff --git a/tools.cpp b/tools.cpp index de0b43c..beded35 100644 --- a/tools.cpp +++ b/tools.cpp @@ -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 diff --git a/tools.h b/tools.h index d830d47..a196dc2 100644 --- a/tools.h +++ b/tools.h @@ -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 { -- cgit v1.2.3