diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 7b679bf2..2df7ff82 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -3,6 +3,7 @@ add_executable( exiv2 exiv2app.hpp actions.cpp actions.hpp getopt.cpp getopt.hpp + app_utils.cpp app_utils.hpp $ ) diff --git a/app/actions.cpp b/app/actions.cpp index a58d467f..d1f601ae 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -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" diff --git a/app/app_utils.cpp b/app/app_utils.cpp new file mode 100644 index 00000000..dec2955c --- /dev/null +++ b/app/app_utils.cpp @@ -0,0 +1,22 @@ +#include "utils.hpp" + +#include +#include + +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 diff --git a/app/app_utils.hpp b/app/app_utils.hpp new file mode 100644 index 00000000..be8db686 --- /dev/null +++ b/app/app_utils.hpp @@ -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_ diff --git a/app/exiv2.cpp b/app/exiv2.cpp index fe97449d..87fb2f99 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -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. diff --git a/src/utils.cpp b/src/utils.cpp index 0ef0f203..72124f6a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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 diff --git a/src/utils.hpp b/src/utils.hpp index 5f63b7d5..42517a7f 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -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_