1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Improved numdigits(), isnumber() and strreplace()

This commit is contained in:
Klaus Schmidinger 2007-07-20 14:25:46 +02:00
parent 57c2b211e4
commit bd36fb5111
3 changed files with 19 additions and 12 deletions

View File

@ -2106,3 +2106,6 @@ Jose Alberto Reguero <jareguero@telefonica.net>
Patrice Staudt <staudt@engsystem.net>
for adding full weekday names to i18n.c for plugins to use
Tobias Bratfisch <tobias@reel-multimedia.com>
for improving numdigits(), isnumber() and strreplace()

View File

@ -5283,3 +5283,4 @@ Video Disk Recorder Revision History
- Updated the Russian OSD texts (thanks to Oleg Roitburd).
- Fixed handling single byte characters >0x7F in Utf8ToArray() (thanks to Udo
Richter).
- Improved numdigits(), isnumber() and strreplace() (thanks to Tobias Bratfisch).

23
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 1.132 2007/07/20 13:17:40 kls Exp $
* $Id: tools.c 1.133 2007/07/20 14:25:46 kls Exp $
*/
#include "tools.h"
@ -158,10 +158,11 @@ char *strreplace(char *s, const char *s1, const char *s2)
int l1 = strlen(s1);
int l2 = strlen(s2);
if (l2 > l1)
s = (char *)realloc(s, strlen(s) + l2 - l1 + 1);
s = (char *)realloc(s, l + l2 - l1 + 1);
char *sof = s + of;
if (l2 != l1)
memmove(s + of + l2, s + of + l1, l - of - l1 + 1);
strncpy(s + of, s2, l2);
memmove(sof + l2, sof + l1, l - of - l1 + 1);
strncpy(sof, s2, l2);
}
return s;
}
@ -252,20 +253,22 @@ bool isempty(const char *s)
int numdigits(int n)
{
char buf[16];
snprintf(buf, sizeof(buf), "%d", n);
return strlen(buf);
int res = 1;
while (n >= 10) {
n /= 10;
res++;
}
return res;
}
bool isnumber(const char *s)
{
if (!*s)
return false;
while (*s) {
do {
if (!isdigit(*s))
return false;
s++;
}
} while (*++s);
return true;
}