]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/oswald_strings.c
Shorten charger plug "tail"
[oswald.git] / ui / oswald_strings.c
index e04da9b444d193eca9635058ceed1a4cf61d84de..44bbeb6997a66ca37cbbeb8303f59d5fcd0e38f4 100644 (file)
@@ -2,9 +2,9 @@
 
 #include "oswald_strings.h"
 
-u16t oswald_strlen(u8t *string)
+uint16_t oswald_strlen(char *string)
 {
-       register i=0;
+       int i=0;
 
        if (string == NULL)
                return 0;
@@ -14,3 +14,35 @@ u16t oswald_strlen(u8t *string)
        return i;
 }
 
+char *itoa(int16_t value, char* result, int base)
+{
+       char *ptr = result, *ptr1 = result, tmp_char;
+       int16_t tmp_value;
+
+       if (result == NULL)
+               return NULL;
+
+       // check that the base if valid
+       if (base < 2 || base > 36) {
+               *result = '\0';
+               return result;
+       }
+
+       do {
+               tmp_value = value;
+               value /= base;
+               *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
+       } while ( value );
+
+       // Apply negative sign
+       if (tmp_value < 0)
+               *ptr++ = '-';
+       *ptr-- = '\0';
+       while (ptr1 < ptr) {
+               tmp_char = *ptr;
+               *ptr--= *ptr1;
+               *ptr1++ = tmp_char;
+       }
+       return result;
+}
+