From 595d062638b85dbcd644a233e2397e1f48cd5eb0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 26 Nov 2019 07:49:23 +1100 Subject: [PATCH] string: add to_upper --- string.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/string.hpp b/string.hpp index 19e9928d..301b027d 100644 --- a/string.hpp +++ b/string.hpp @@ -19,6 +19,38 @@ namespace cruft { std::string to_utf8 (const wchar_t*); std::string to_utf8 (const std::wstring&); + + + /// Convert the provided string to all upper case + inline std::string + to_upper (std::string &&val) + { + std::transform ( + std::begin (val), + std::end (val), + std::begin (val), + ::toupper + ); + return std::move (val); + } + + + /// Convert the provided string to all upper case + inline std::string + to_upper (std::string const &val) + { + std::string res; + res.reserve (val.size ()); + + std::transform ( + std::begin (val), + std::end (val), + std::back_inserter (res), + ::toupper + ); + + return res; + } }