Utils::strtol only used in the app
parent
8c6e22e6aa
commit
7c6a7aefc2
@ -0,0 +1,22 @@
|
|||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
namespace Util
|
||||||
|
{
|
||||||
|
bool strtol(const char* nptr, long& n)
|
||||||
|
{
|
||||||
|
if (!nptr || *nptr == '\0')
|
||||||
|
return false;
|
||||||
|
char* endptr = nullptr;
|
||||||
|
long tmp = std::strtol(nptr, &endptr, 10);
|
||||||
|
if (*endptr != '\0')
|
||||||
|
return false;
|
||||||
|
if (tmp == LONG_MAX || tmp == LONG_MIN)
|
||||||
|
return false;
|
||||||
|
n = tmp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Util
|
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef APP_UTILS_HPP_
|
||||||
|
#define APP_UTILS_HPP_
|
||||||
|
|
||||||
|
namespace Util {
|
||||||
|
/*!
|
||||||
|
@brief Convert a C string to a long value, which is returned in n.
|
||||||
|
Returns true if the conversion is successful, else false.
|
||||||
|
n is not modified if the conversion is unsuccessful. See strtol(2).
|
||||||
|
*/
|
||||||
|
bool strtol(const char* nptr, long& n);
|
||||||
|
} // namespace Util
|
||||||
|
|
||||||
|
#endif // #ifndef UTILS_HPP_
|
Loading…
Reference in New Issue