Skip to content

Commit

Permalink
Added toLowerInPlace and toUpperInPlace and tweaked comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhoux committed Dec 29, 2023
1 parent dd6f53a commit 613b4d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions include/cinder/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions src/cinder/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 613b4d1

Please sign in to comment.