summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS3
-rw-r--r--HISTORY1
-rw-r--r--tools.c27
3 files changed, 19 insertions, 12 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 264d24b0..1db7f3ae 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -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()
diff --git a/HISTORY b/HISTORY
index 0043cc4e..10876b2d 100644
--- a/HISTORY
+++ b/HISTORY
@@ -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).
diff --git a/tools.c b/tools.c
index 46b691b9..dc91d11a 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.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) {
- if (!isdigit(*s))
- return false;
- s++;
- }
+ do {
+ if (!isdigit(*s))
+ return false;
+ } while (*++s);
return true;
}