Mbed port of RMCIOS. www.rmcios.fi https://github.com/fkorhone/

Dependencies:   mbed mbed-rtos EthernetInterface

Committer:
ransu
Date:
Thu Dec 27 19:21:42 2018 +0000
Revision:
0:aeaa6d2120a3
Initial commit to public.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ransu 0:aeaa6d2120a3 1 #include "string-conversion.h"
ransu 0:aeaa6d2120a3 2
ransu 0:aeaa6d2120a3 3 #include <stdlib.h>
ransu 0:aeaa6d2120a3 4 #include <stdio.h>
ransu 0:aeaa6d2120a3 5
ransu 0:aeaa6d2120a3 6 /* String to float converter
ransu 0:aeaa6d2120a3 7 * @param str String to convert from
ransu 0:aeaa6d2120a3 8 * returns the converted value. Returns 0 on failure. */
ransu 0:aeaa6d2120a3 9 int string_to_integer (const char *str)
ransu 0:aeaa6d2120a3 10 {
ransu 0:aeaa6d2120a3 11 return strtol (str, NULL, 0);
ransu 0:aeaa6d2120a3 12 }
ransu 0:aeaa6d2120a3 13
ransu 0:aeaa6d2120a3 14 /* String to float converter
ransu 0:aeaa6d2120a3 15 * @param str String to convert from
ransu 0:aeaa6d2120a3 16 * returns the converted value. Returns 0 on failure. */
ransu 0:aeaa6d2120a3 17 double string_to_float (const char *str)
ransu 0:aeaa6d2120a3 18 {
ransu 0:aeaa6d2120a3 19 return strtof (str, NULL);
ransu 0:aeaa6d2120a3 20 }
ransu 0:aeaa6d2120a3 21
ransu 0:aeaa6d2120a3 22 /* Integer to string converter
ransu 0:aeaa6d2120a3 23 * @param buffer buffer to write to
ransu 0:aeaa6d2120a3 24 * @param len size of buffer
ransu 0:aeaa6d2120a3 25 * @param value number to convert
ransu 0:aeaa6d2120a3 26 * @return number of characters the full string representation needs. */
ransu 0:aeaa6d2120a3 27 int integer_to_string (char *buffer, int len, int value)
ransu 0:aeaa6d2120a3 28 {
ransu 0:aeaa6d2120a3 29 return snprintf (buffer, len, "%d", value);
ransu 0:aeaa6d2120a3 30 }
ransu 0:aeaa6d2120a3 31
ransu 0:aeaa6d2120a3 32 /* Float to string converter
ransu 0:aeaa6d2120a3 33 * @param buffer buffer to write to
ransu 0:aeaa6d2120a3 34 * @param len size of buffer
ransu 0:aeaa6d2120a3 35 * @param value Number to convert
ransu 0:aeaa6d2120a3 36 * @return number of characters the full string representation needs.*/
ransu 0:aeaa6d2120a3 37 int float_to_string (char *buffer, int len, double value)
ransu 0:aeaa6d2120a3 38 {
ransu 0:aeaa6d2120a3 39 return snprintf (buffer, len, "%g", value);
ransu 0:aeaa6d2120a3 40 }
ransu 0:aeaa6d2120a3 41
ransu 0:aeaa6d2120a3 42
ransu 0:aeaa6d2120a3 43