nlib
StrTo.h File Reference

Wrapper functions for safe use of C standard functions like strtol and strtoul. More...

#include "nn/nlib/Config.h"

Go to the source code of this file.

Namespaces

 nn::nlib
 Implements common features and features that are highly platform-dependent. Also refer to nlib Platform APIs. nlib_ns is an alias.
 

Functions

errno_t nn::nlib::StrTo (const char *s, int base, int32_t *v) noexcept
 Converts the string s into an int32_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, int64_t *v) noexcept
 Converts the string s into an int64_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, uint32_t *v) noexcept
 Converts the string s into a uint32_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, uint64_t *v) noexcept
 Converts the string s into a uint64_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, double *v) noexcept
 Converts the string s into a double type. More...
 
errno_t nn::nlib::StrTo (const char *s, float *v) noexcept
 Converts the string s into a float type. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, int8_t *v) noexcept
 Converts the string s into an int8_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, int16_t *v) noexcept
 Converts the string s into an int16_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, uint8_t *v) noexcept
 Converts the string s into a uint8_t-type integer. More...
 
errno_t nn::nlib::StrTo (const char *s, int base, uint16_t *v) noexcept
 Converts the string s into a uint16_t-type integer. More...
 

Detailed Description

Wrapper functions for safe use of C standard functions like strtol and strtoul.

Description
The C standard functions strtol and strtoul are popular ways to convert strings into numerical values, but you must note the following.
  • Before calling the functions you must set errno=0. Functions like strtol and strtoul may set errno and return an error value that is in the normal range of return values.
  • Functions like strtol and strtoul skip leading white spaces.
  • Functions like strtol and strtoul have different error values.
  • In some cases, strtoul does not generate an error on negative numbers.
Using these wrapper functions shields you from these troublesome problems and lets you code for the conversion process in an intuitive fashion.

Definition in file StrTo.h.