From 0ec2063b5ad4a6b9574efa6365ac4bf026211e9d Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 13 Jan 2008 11:26:30 +0100 Subject: [PATCH] Added cString::Truncate() --- HISTORY | 1 + tools.c | 12 +++++++++++- tools.h | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index 0969a5af..13ee47ea 100644 --- a/HISTORY +++ b/HISTORY @@ -5540,3 +5540,4 @@ Video Disk Recorder Revision History no menu open it will show the info of the current broadcast or replay. - cTimeMs now uses the monotonic clock, if available (thanks to Petri Hintukainen). - Fixed cVector::Clear() and cStringList::Clear(). +- Added cString::Truncate(). diff --git a/tools.c b/tools.c index 79b7c347..98d2501f 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.139 2008/01/01 15:10:07 kls Exp $ + * $Id: tools.c 1.140 2008/01/13 11:26:30 kls Exp $ */ #include "tools.h" @@ -873,6 +873,16 @@ cString &cString::operator=(const cString &String) return *this; } +cString &cString::Truncate(int Index) +{ + int l = strlen(s); + if (Index < 0) + Index = l + Index; + if (Index >= 0 && Index < l) + s[Index] = 0; + return *this; +} + cString cString::sprintf(const char *fmt, ...) { va_list ap; diff --git a/tools.h b/tools.h index 1239176d..3c804b52 100644 --- a/tools.h +++ b/tools.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 1.109 2008/01/01 15:09:25 kls Exp $ + * $Id: tools.h 1.110 2008/01/13 11:22:26 kls Exp $ */ #ifndef __TOOLS_H @@ -159,6 +159,7 @@ public: operator const char * () const { return s; } // for use in (const char *) context const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.) cString &operator=(const cString &String); + cString &Truncate(int Index); ///< Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string). static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); };