Utils::strtol only used in the app

main
Luis Díaz Más 3 years ago committed by Luis Diaz
parent 8c6e22e6aa
commit 7c6a7aefc2

@ -3,6 +3,7 @@ add_executable( exiv2
exiv2app.hpp
actions.cpp actions.hpp
getopt.cpp getopt.hpp
app_utils.cpp app_utils.hpp
$<TARGET_OBJECTS:exiv2lib_int>
)

@ -24,8 +24,10 @@
// included header files
#include "config.h"
#include "app_utils.hpp"
#include "actions.hpp"
#include "exiv2app.hpp"
#include "image.hpp"
#include "jpgimage.hpp"
#include "xmpsidecar.hpp"

@ -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_

@ -22,8 +22,10 @@
// include local header files which are not part of libexiv2
#include "actions.hpp"
#include "convert.hpp"
#include "app_utils.hpp"
#include "exiv2app.hpp"
#include "convert.hpp"
#include "futils.hpp"
#include "getopt.hpp"
#include "i18n.h" // NLS support.

@ -98,15 +98,4 @@ namespace Util {
return b.substr(idx);
}
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

@ -63,13 +63,6 @@ namespace Util {
to the end of the string.
*/
std::string suffix(const std::string& path);
/*!
@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…
Cancel
Save