From 613b4d185c1df04530423c6e9371a3e95c786018 Mon Sep 17 00:00:00 2001 From: paulhoux Date: Fri, 29 Dec 2023 17:57:49 +0100 Subject: [PATCH] Added toLowerInPlace and toUpperInPlace and tweaked comments. --- include/cinder/Utilities.h | 8 ++++++-- src/cinder/Utilities.cpp | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/cinder/Utilities.h b/include/cinder/Utilities.h index 012e83a0ce..0379482302 100644 --- a/include/cinder/Utilities.h +++ b/include/cinder/Utilities.h @@ -130,9 +130,13 @@ CI_API char charToLower( const char c ); //! Converts the character \a c to uppercase. Not Unicode-aware. CI_API char charToUpper( const char c ); -//! returns a copy of \a str with all characters converted to lowercase (using std::tolower()). +//! converts all characters to lowercase (using std::tolower()) in \a str. Not Unicode-aware. +CI_API void toLowerInPlace( std::string &str ); +//! returns a copy of \a str with all characters converted to lowercase (using std::tolower()). Not Unicode-aware. CI_API std::string toLower( std::string str ); -//! returns a copy of \a str with all characters converted to uppercase (using std::toupper()). +//! converts all characters to uppercase (using std::toupper()) in \a str.Not Unicode-aware. +CI_API void toUpperInPlace( std::string &str ); +//! returns a copy of \a str with all characters converted to uppercase (using std::toupper()). Not Unicode-aware. CI_API std::string toUpper( std::string str ); //! replaces all instances of \a find with \a replace in \a str. Not Unicode-aware. diff --git a/src/cinder/Utilities.cpp b/src/cinder/Utilities.cpp index 4f2134feb9..e69bec214b 100644 --- a/src/cinder/Utilities.cpp +++ b/src/cinder/Utilities.cpp @@ -252,15 +252,25 @@ char charToUpper( const char c ) return c; } -std::string toLower( std::string str ) +void toLowerInPlace( std::string &str ) { std::transform( str.begin(), str.end(), str.begin(), []( unsigned char c ) { return std::tolower( c ); } ); +} + +std::string toLower( std::string str ) +{ + toLowerInPlace( str ); return str; } -std::string toUpper( std::string str ) +void toUpperInPlace( std::string &str ) { std::transform( str.begin(), str.end(), str.begin(), []( unsigned char c ) { return std::toupper( c ); } ); +} + +std::string toUpper( std::string str ) +{ + toUpperInPlace( str ); return str; }