Longan Nano
Longan Nano Demo
|
String <-> Number conversion using standard c strings to avoid std::string under the hood. More...
#include <embedded_string.hpp>
Public Types | |
enum | _Config { SAFETY_CHECKS = true, DIGIT8 = 3, DIGIT16 = 5, DIGIT32 = 10, DIGIT_ENG = 4, STRING_SIGN_SIZE = 1, STRING_TERMINATOR_SIZE = 1, TERMINATOR = '\0', STRING_SIZE_U8 = DIGIT8 +STRING_TERMINATOR_SIZE, STRING_SIZE_S8 = DIGIT8 +STRING_SIGN_SIZE +STRING_TERMINATOR_SIZE, STRING_SIZE_U16 = DIGIT16 +STRING_TERMINATOR_SIZE, STRING_SIZE_S16 = DIGIT16 +STRING_SIGN_SIZE +STRING_TERMINATOR_SIZE, STRING_SIZE_U32 = DIGIT32 +STRING_TERMINATOR_SIZE, STRING_SIZE_S32 = DIGIT32 +STRING_SIGN_SIZE +STRING_TERMINATOR_SIZE, STRING_SIZE_UENG = 7, STRING_SIZE_SENG = 8 } |
Configurations for the String class. More... | |
typedef enum User::String::_Config | Config |
Configurations for the String class. More... | |
Public Member Functions | |
String (void) | |
Constructor String | void. More... | |
~String (void) | |
Destructor String | void. More... | |
Static Public Member Functions | |
static uint8_t | num_to_str (uint8_t num, uint8_t str_len, char *str) |
public static method num_to_str | uint8_t | uint8_t | char * | More... | |
static uint8_t | num_to_str (int8_t num, uint8_t str_len, char *str) |
public static method num_to_str | int8_t | uint8_t | char * | More... | |
static uint8_t | num_to_str (uint16_t num, uint8_t str_len, char *str) |
public static method num_to_str | uint16_t | uint8_t | char * | More... | |
static uint8_t | num_to_str (int16_t num, uint8_t str_len, char *str) |
public static method num_to_str | int16_t | uint8_t | const char * | More... | |
static uint8_t | num_to_str (uint32_t num, uint8_t str_len, char *str) |
public static method num_to_str | uint32_t | uint8_t | char * | More... | |
static uint8_t | num_to_str (int32_t num, uint8_t str_len, char *str) |
public static method num_to_str | int32_t | uint8_t | const char * | More... | |
static uint8_t | num_to_eng (uint32_t num, int8_t num_exp, uint8_t str_len, char *str) |
public static method num_to_eng | uint32_t | uint8_t | char * | More... | |
static uint8_t | num_to_eng (int32_t num, int8_t num_exp, uint8_t str_len, char *str) |
public static method num_to_eng | int32_t | uint8_t | const char * | More... | |
static uint8_t | num_to_eng (uint32_t num, uint8_t str_len, char *str) |
public static method num_to_eng | uint32_t | uint8_t | const char * | More... | |
static uint8_t | num_to_eng (int32_t num, uint8_t str_len, char *str) |
public static method num_to_eng | int32_t | uint8_t | const char * | More... | |
String <-> Number conversion using standard c strings to avoid std::string under the hood.
2020-07-27
Encapsulate in class form
Transplant u8, s8, u16, s16, u32 and s32 methods from the 2019-11-07 At_string V2 library
Added safety checks and option to disable them in release
Use C++ overloading and make use of num_to_str method. No longer calling the wrong conversion method
Tested U8 and S8 methods. Test safety by providing shorter string: SUCCESS
U16 and S16 methods can call the U8 conversion when number is small enough
Tested U16 and S16 methods: SUCCESS
Tested U32 and S32. The test example only test S16 as there are problems with d
Engineering format string
2020-07-29
Tested signed and unsigned integer engineering format string generation
Added base 10^X exponent to eng conversion. It's meant to allow user to specify a multiplier when using inegers. e.g. 1000 means 100.0%
2020-08-08
Clean Up Doxygen documentation
typedef enum User::String::_Config User::String::Config |
Configurations for the String class.
Configurations for the String class.
|
inline |
|
inline |
|
inlinestatic |
public static method num_to_eng | int32_t | uint8_t | const char * |
num | | int32_t | number to be converted |
num_exp | | int8_t | base 10^x eponent of the number. E.G. the user might have provided a number in millivolts, exponent -3 |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. Must be at least 7 |
str | | const char * | return string provied by the caller |
wrapper
|
inlinestatic |
public static method num_to_eng | int32_t | uint8_t | const char * |
num | | int32_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. Must be at least 7 |
str | | const char * | return string provied by the caller |
wrapper
|
inlinestatic |
public static method
num_to_eng | uint32_t | uint8_t | char * |
num | | int32_t | number to be converted |
num_exp | | int8_t | base 10^x eponent of the number. E.G. the user might have provided a number in millivolts, exponent -3 |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. Must be at least 7 |
str | | const char * | return string provied by the caller |
convert a S32 into an enginnering number format. Four significant digits with SI suffix always uses 6 characters X.XXX{SI} XX.XX{SI} XXX.X{SI} SI Suffixes Exponents index | -6 -5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5 +6 exp | -18 -15 -12 -9 -6 -3 0 +3 +6 +9 +12 +15 +18 suffix | a f p n u m K M G T P E
|
inlinestatic |
public static method num_to_eng | uint32_t | uint8_t | const char * |
num | | int32_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. Must be at least 7 |
str | | const char * | return string provied by the caller |
wrapper
|
inlinestatic |
public static method num_to_str | int16_t | uint8_t | const char * |
num | | int16_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. "XXX\0" str_len = 4 |
str | | const char * | return string provied by the caller |
Convert an int16_t to string
convert a S16 into a string. Does mostly sign conversion. Make use of the U8 and U16 methods for the actual conversion.
|
inlinestatic |
public static method num_to_str | int32_t | uint8_t | const char * |
num | | int32_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. "XXX\0" str_len = 4 |
str | | const char * | return string provied by the caller |
convert a S32 into a string. Does mostly sign conversion. Make use of the U8 and U16 methods for the actual conversion.
|
inlinestatic |
public static method num_to_str | int8_t | uint8_t | char * |
num | | int8_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. "XXX\0" str_len = 4 |
str | | const char * | return string provied by the caller |
convert a S8 into a string. Mostly does sign correction. Make use of the U8 method for the actual conversion.
|
inlinestatic |
public static method num_to_str | uint16_t | uint8_t | char * |
num | | uint16_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. "XXX\0" str_len = 4 |
str | | const char * | return string provied by the caller |
convert a U16 into a string. Make use of the U8 method for small numbers
|
inlinestatic |
public static method num_to_str | uint32_t | uint8_t | char * |
num | | uint32_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. "XXX\0" str_len = 4 |
str | | const char * | return string provied by the caller |
convert a U32 into a string
|
inlinestatic |
public static method num_to_str | uint8_t | uint8_t | char * |
num | | uint8_t | number to be converted |
str_len | | uint8_t | length of the provided string. Avoids overflow. Include terminator. "XXX\0" str_len = 4 |
str | | const char * | return string provied by the caller |
convert a U8 into a string