From 35ae04510fdc9336ec1949dfe6701748c0cebfe6 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 1 May 2019 12:30:39 +1000 Subject: [PATCH] ascii: add try_lower --- ascii.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ascii.hpp b/ascii.hpp index b2cf627c..973fc253 100644 --- a/ascii.hpp +++ b/ascii.hpp @@ -131,6 +131,19 @@ namespace cruft::ascii { } + ///------------------------------------------------------------------------ + /// Convert an ASCII character into a lower case character if it is upper + /// case, else return it unchanged. + /// + /// If you know the character is always upper case then prefer to_lower. + constexpr inline + char + try_lower (char c) noexcept + { + return is_upper (c) ? to_lower (c) : c; + } + + /////////////////////////////////////////////////////////////////////////// /// Returns true if the supplied ASCII character is whitespace. constexpr inline