From a75d11a7e6984b3df15da9677fbd49ee8de7a9c3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 14 Sep 2016 14:42:15 +0200 Subject: [PATCH] Add a toLower utility function --- src/libutil/util.cc | 10 ++++++++++ src/libutil/util.hh | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 7efaf3e89..87e97c20f 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -1087,6 +1088,15 @@ bool hasSuffix(const string & s, const string & suffix) } +std::string toLower(const std::string & s) +{ + std::string r(s); + for (auto & c : r) + c = std::tolower(c); + return r; +} + + string decodeOctalEscaped(const string & s) { string r; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 69c723ad2..7aeca0edc 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -334,6 +334,10 @@ bool hasPrefix(const string & s, const string & prefix); bool hasSuffix(const string & s, const string & suffix); +/* Convert a string to lower case. */ +std::string toLower(const std::string & s); + + /* Escape a string that contains octal-encoded escape codes such as used in /etc/fstab and /proc/mounts (e.g. "foo\040bar" decodes to "foo bar"). */