Longan Nano
Longan Nano Demo
User::String Class Reference

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...
 

Detailed Description

String <-> Number conversion using standard c strings to avoid std::string under the hood.

Author
Orso Eric
Version
2020-08-08
Bug:
None
Warning
None


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

Member Typedef Documentation

◆ Config

Configurations for the String class.

Member Enumeration Documentation

◆ _Config

Configurations for the String class.

Enumerator
SAFETY_CHECKS 
DIGIT8 
DIGIT16 
DIGIT32 
DIGIT_ENG 
STRING_SIGN_SIZE 
STRING_TERMINATOR_SIZE 
TERMINATOR 
STRING_SIZE_U8 
STRING_SIZE_S8 
STRING_SIZE_U16 
STRING_SIZE_S16 
STRING_SIZE_U32 
STRING_SIZE_S32 
STRING_SIZE_UENG 
STRING_SIZE_SENG 

Constructor & Destructor Documentation

◆ String()

User::String::String ( void  )
inline

Constructor String | void.

Returns
no return

Empty constructor


RETURN

◆ ~String()

User::String::~String ( void  )
inline

Destructor String | void.

Returns
no return

Empty destructor


RETURN

Member Function Documentation

◆ num_to_eng() [1/4]

static uint8_t User::String::num_to_eng ( int32_t  num,
int8_t  num_exp,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_eng | int32_t | uint8_t | const char * |

Parameters
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
Returns
uint8_t | number of digits written in the string, not including terminator


wrapper

Here is the call graph for this function:

◆ num_to_eng() [2/4]

static uint8_t User::String::num_to_eng ( int32_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_eng | int32_t | uint8_t | const char * |

Parameters
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
Returns
uint8_t | number of digits written in the string, not including terminator


wrapper

Here is the call graph for this function:

◆ num_to_eng() [3/4]

static uint8_t User::String::num_to_eng ( uint32_t  num,
int8_t  num_exp,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method
num_to_eng | uint32_t | uint8_t | char * |

Parameters
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
Returns
uint8_t | number of digits written in the string, not including terminator

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

Here is the caller graph for this function:

◆ num_to_eng() [4/4]

static uint8_t User::String::num_to_eng ( uint32_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_eng | uint32_t | uint8_t | const char * |

Parameters
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
Returns
uint8_t | number of digits written in the string, not including terminator


wrapper

Here is the call graph for this function:

◆ num_to_str() [1/6]

static uint8_t User::String::num_to_str ( int16_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_str | int16_t | uint8_t | const char * |

Parameters
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
Returns
uint8_t | number of digits written in the string

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.

Here is the call graph for this function:

◆ num_to_str() [2/6]

static uint8_t User::String::num_to_str ( int32_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_str | int32_t | uint8_t | const char * |

Parameters
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
Returns
uint8_t | number of digits written in the string


convert a S32 into a string. Does mostly sign conversion. Make use of the U8 and U16 methods for the actual conversion.

Here is the call graph for this function:

◆ num_to_str() [3/6]

static uint8_t User::String::num_to_str ( int8_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_str | int8_t | uint8_t | char * |

Parameters
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
Returns
uint8_t | number of digits written in the string


convert a S8 into a string. Mostly does sign correction. Make use of the U8 method for the actual conversion.

Here is the call graph for this function:

◆ num_to_str() [4/6]

static uint8_t User::String::num_to_str ( uint16_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_str | uint16_t | uint8_t | char * |

Parameters
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
Returns
uint8_t | number of digits written in the string E.g. writing "255" returns 3. writing "0" returns 1 | 0 means no digits were written: fail


convert a U16 into a string. Make use of the U8 method for small numbers

Here is the call graph for this function:

◆ num_to_str() [5/6]

static uint8_t User::String::num_to_str ( uint32_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_str | uint32_t | uint8_t | char * |

Parameters
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
Returns
uint8_t | number of digits written in the string E.g. writing "255" returns 3. writing "0" returns 1 | 0 means no digits were written: fail


convert a U32 into a string

Here is the call graph for this function:

◆ num_to_str() [6/6]

static uint8_t User::String::num_to_str ( uint8_t  num,
uint8_t  str_len,
char *  str 
)
inlinestatic

public static method num_to_str | uint8_t | uint8_t | char * |

Parameters
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
Returns
uint8_t | number of digits written in the string E.g. writing "255" returns 3. writing "0" returns 1 | 0 means no digits were written: fail


convert a U8 into a string

Here is the caller graph for this function:

The documentation for this class was generated from the following file: