aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/current-process.cc1
-rw-r--r--src/libutil/file-system.hh2
-rw-r--r--src/libutil/logging.cc1
-rw-r--r--src/libutil/processes.hh2
-rw-r--r--src/libutil/strings.cc39
-rw-r--r--src/libutil/strings.hh21
6 files changed, 43 insertions, 23 deletions
diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc
index c64dd1e0d..3c037c33f 100644
--- a/src/libutil/current-process.cc
+++ b/src/libutil/current-process.cc
@@ -5,6 +5,7 @@
#include "namespaces.hh"
#include "signals.hh"
#include "strings.hh"
+#include <math.h>
#ifdef __APPLE__
# include <mach-o/dyld.h>
diff --git a/src/libutil/file-system.hh b/src/libutil/file-system.hh
index b9b753980..6c1923d55 100644
--- a/src/libutil/file-system.hh
+++ b/src/libutil/file-system.hh
@@ -13,8 +13,6 @@
#include <dirent.h>
#include <unistd.h>
-#include <boost/lexical_cast.hpp>
-
#include <functional>
#include <optional>
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index febbfdb55..b01bb4dd4 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -6,6 +6,7 @@
#include "terminal.hh"
#include <atomic>
+#include <sstream>
#include <nlohmann/json.hpp>
namespace nix {
diff --git a/src/libutil/processes.hh b/src/libutil/processes.hh
index 91a4edfd2..b84fc7c4b 100644
--- a/src/libutil/processes.hh
+++ b/src/libutil/processes.hh
@@ -10,8 +10,6 @@
#include <unistd.h>
#include <signal.h>
-#include <boost/lexical_cast.hpp>
-
#include <functional>
#include <map>
#include <optional>
diff --git a/src/libutil/strings.cc b/src/libutil/strings.cc
index 9cb319cce..947478481 100644
--- a/src/libutil/strings.cc
+++ b/src/libutil/strings.cc
@@ -1,4 +1,6 @@
#include "strings.hh"
+#include <boost/lexical_cast.hpp>
+#include <stdint.h>
namespace nix {
@@ -89,6 +91,43 @@ std::string Rewriter::operator()(std::string s)
return s;
}
+template<class N>
+std::optional<N> string2Int(const std::string_view s)
+{
+ if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed)
+ return std::nullopt;
+ try {
+ return boost::lexical_cast<N>(s.data(), s.size());
+ } catch (const boost::bad_lexical_cast &) {
+ return std::nullopt;
+ }
+}
+
+// Explicitly instantiated in one place for faster compilation
+template std::optional<unsigned char> string2Int<unsigned char>(const std::string_view s);
+template std::optional<unsigned short> string2Int<unsigned short>(const std::string_view s);
+template std::optional<unsigned int> string2Int<unsigned int>(const std::string_view s);
+template std::optional<unsigned long> string2Int<unsigned long>(const std::string_view s);
+template std::optional<unsigned long long> string2Int<unsigned long long>(const std::string_view s);
+template std::optional<signed char> string2Int<signed char>(const std::string_view s);
+template std::optional<signed short> string2Int<signed short>(const std::string_view s);
+template std::optional<signed int> string2Int<signed int>(const std::string_view s);
+template std::optional<signed long> string2Int<signed long>(const std::string_view s);
+template std::optional<signed long long> string2Int<signed long long>(const std::string_view s);
+
+template<class N>
+std::optional<N> string2Float(const std::string_view s)
+{
+ try {
+ return boost::lexical_cast<N>(s.data(), s.size());
+ } catch (const boost::bad_lexical_cast &) {
+ return std::nullopt;
+ }
+}
+
+template std::optional<double> string2Float<double>(const std::string_view s);
+template std::optional<float> string2Float<float>(const std::string_view s);
+
std::string toLower(const std::string & s)
{
diff --git a/src/libutil/strings.hh b/src/libutil/strings.hh
index daeb5be50..03dff8160 100644
--- a/src/libutil/strings.hh
+++ b/src/libutil/strings.hh
@@ -4,7 +4,6 @@
#include "error.hh"
#include "types.hh"
-#include <boost/lexical_cast.hpp>
#include <vector>
namespace nix {
@@ -130,16 +129,7 @@ inline std::string rewriteStrings(std::string s, const StringMap & rewrites)
* Parse a string into an integer.
*/
template<class N>
-std::optional<N> string2Int(const std::string_view s)
-{
- if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed)
- return std::nullopt;
- try {
- return boost::lexical_cast<N>(s.data(), s.size());
- } catch (const boost::bad_lexical_cast &) {
- return std::nullopt;
- }
-}
+std::optional<N> string2Int(const std::string_view s);
/**
* Like string2Int(), but support an optional suffix 'K', 'M', 'G' or
@@ -169,14 +159,7 @@ N string2IntWithUnitPrefix(std::string_view s)
* Parse a string into a float.
*/
template<class N>
-std::optional<N> string2Float(const std::string_view s)
-{
- try {
- return boost::lexical_cast<N>(s.data(), s.size());
- } catch (const boost::bad_lexical_cast &) {
- return std::nullopt;
- }
-}
+std::optional<N> string2Float(const std::string_view s);
/**