From 4402688c9c63e9885de1bf99cd718150b036ac7a Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 5 Mar 2024 00:13:20 +0800 Subject: [PATCH] feat add ToUpper,ToLower --- include/sled/strings/utils.h | 2 ++ src/strings/utils.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/sled/strings/utils.h b/include/sled/strings/utils.h index b5e8aeb..790c2ad 100644 --- a/include/sled/strings/utils.h +++ b/include/sled/strings/utils.h @@ -6,6 +6,8 @@ namespace sled { +char ToLower(char c); +char ToUpper(char c); std::string ToLower(const std::string &str); std::string ToUpper(const std::string &str); std::string ToHex(const std::string &str); diff --git a/src/strings/utils.cc b/src/strings/utils.cc index a5c981a..6a419a7 100644 --- a/src/strings/utils.cc +++ b/src/strings/utils.cc @@ -1,8 +1,39 @@ #include "sled/strings/utils.h" #include +#include namespace sled { +char +ToLower(char c) +{ + return ::tolower(c); +} + +char +ToUpper(char c) +{ + return ::toupper(c); +} + +std::string +ToLower(const std::string &str) +{ + std::string result; + std::transform(str.begin(), str.end(), std::back_inserter(result), + ::tolower); + return result; +} + +std::string +ToUpper(const std::string &str) +{ + std::string result; + std::transform(str.begin(), str.end(), std::back_inserter(result), + ::toupper); + return result; +} + std::string StrJoin(const std::vector &strings, const std::string &delim,