Added cString::Append(char)

This commit is contained in:
Klaus Schmidinger 2023-12-29 10:24:29 +01:00
parent 6458f8b581
commit f0bbf64da0
2 changed files with 19 additions and 2 deletions

18
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 5.7 2022/11/22 14:33:48 kls Exp $
* $Id: tools.c 5.8 2023/12/29 10:24:29 kls Exp $
*/
#include "tools.h"
@ -1130,6 +1130,22 @@ cString &cString::Append(const char *String)
return *this;
}
cString &cString::Append(char c)
{
if (c) {
int l1 = s ? strlen(s) : 0;
int l2 = 1;
if (char *p = (char *)realloc(s, l1 + l2 + 1)) {
s = p;
*(s + l1) = c;
*(s + l1 + 1) = 0;
}
else
esyslog("ERROR: out of memory");
}
return *this;
}
cString &cString::Truncate(int Index)
{
int l = strlen(s);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.h 5.6 2021/05/26 13:37:53 kls Exp $
* $Id: tools.h 5.7 2023/12/29 10:21:59 kls Exp $
*/
#ifndef __TOOLS_H
@ -189,6 +189,7 @@ public:
cString &operator=(const cString &String);
cString &operator=(const char *String);
cString &Append(const char *String);
cString &Append(char c);
cString &Truncate(int Index); ///< Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string).
cString &CompactChars(char c); ///< Compact any sequence of characters 'c' to a single character, and strip all of them from the beginning and end of this string.
static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));