]> git.itanic.dy.fi Git - rrdd/commitdiff
string.c: Use existing string helpers
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 22 Feb 2012 20:02:02 +0000 (22:02 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 22 Feb 2012 20:02:02 +0000 (22:02 +0200)
Since we have those fancy helpers, why not use them? Also, add one
extra for skipping float nubers for extra handiness.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
string.c
string.h

index a82bc02c5c7327b3b030d636d5a55ab4d08a78c6..ca90cb57c640cda70d315bfa6a6ea8e05cb8a246 100644 (file)
--- a/string.c
+++ b/string.c
@@ -9,9 +9,7 @@ int dec_to_int(char *src, char **dst)
        ret = atoi(src);
 
        if (dst) {
-               while(((*src >= '0') && (*src <= '9')) && *src)
-                       src++;
-               *dst = src;
+               *dst = skip_numbers(src);
        }
 
        return ret;
@@ -26,9 +24,7 @@ long long dec_to_longlong(char *src, char **dst)
        ret = atoll(src);
 
        if (dst) {
-               while(((*src >= '0') && (*src <= '9')) && *src)
-                       src++;
-               *dst = src;
+               *dst = skip_numbers(src);
        }
 
        return ret;
@@ -43,9 +39,7 @@ float dec_to_float(char *src, char **dst)
        ret = atof(src);
 
        if (dst) {
-               while((((*src >= '0') && (*src <= '9')) || (*src =='.')) && *src)
-                       src++;
-               *dst = src;
+               *dst = skip_float_numbers(src);
        }
 
        return ret;
index 31ac799393b695e04da48ec308a7deb26cf8cd5a..87af1bfdd0fb954a4b187db3dd85377c50933256 100644 (file)
--- a/string.h
+++ b/string.h
@@ -26,4 +26,12 @@ static inline char *skip_numbers(char *str)
        return str;
 }
 
+static inline char *skip_float_numbers(char *str)
+{
+       while(isdigit(*str) || (*str == '.'))
+               str++;
+
+       return str;
+}
+
 #endif