Added cString::Truncate()

This commit is contained in:
Klaus Schmidinger 2008-01-13 11:26:30 +01:00
parent fe2568082a
commit 0ec2063b5a
3 changed files with 14 additions and 2 deletions

View File

@ -5540,3 +5540,4 @@ Video Disk Recorder Revision History
no menu open it will show the info of the current broadcast or replay. 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). - cTimeMs now uses the monotonic clock, if available (thanks to Petri Hintukainen).
- Fixed cVector::Clear() and cStringList::Clear(). - Fixed cVector::Clear() and cStringList::Clear().
- Added cString::Truncate().

12
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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" #include "tools.h"
@ -873,6 +873,16 @@ cString &cString::operator=(const cString &String)
return *this; 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, ...) cString cString::sprintf(const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef __TOOLS_H
@ -159,6 +159,7 @@ public:
operator const char * () const { return s; } // for use in (const char *) context 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.) const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.)
cString &operator=(const cString &String); 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))); static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
}; };