New utility functions: toUpper() and toLower()

This commit is contained in:
Olivier Teulière 2012-12-22 00:52:20 +01:00
parent 05605a63ae
commit b039d55c81
2 changed files with 27 additions and 0 deletions

View file

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include <algorithm>
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
#include <cstdarg> #include <cstdarg>
@ -287,6 +288,22 @@ string centerAndConvert(const wstring &iWstr, unsigned int iLength, char c)
} }
wstring toUpper(const wstring &iWstr)
{
wstring str = iWstr;
std::transform(str.begin(), str.end(), str.begin(), towupper);
return str;
}
wstring toLower(const wstring &iWstr)
{
wstring str = iWstr;
std::transform(str.begin(), str.end(), str.begin(), towlower);
return str;
}
unsigned int readFromUTF8(wchar_t *oString, unsigned int iWideSize, unsigned int readFromUTF8(wchar_t *oString, unsigned int iWideSize,
const char *iBuffer, unsigned int iBufSize, const char *iBuffer, unsigned int iBufSize,
const string &iContext) const string &iContext)

View file

@ -83,6 +83,16 @@ string padAndConvert(const wstring &iWstr, unsigned int iLength,
string centerAndConvert(const wstring &iWstr, unsigned int iLength, string centerAndConvert(const wstring &iWstr, unsigned int iLength,
char c = ' '); char c = ' ');
/**
* Return the upper case version of the given string
*/
wstring toUpper(const wstring &iWstr);
/**
* Return the lower case version of the given string
*/
wstring toLower(const wstring &iWstr);
/** /**
* Utility function to convert a char* buffer encoded in UTF-8 into a * Utility function to convert a char* buffer encoded in UTF-8 into a
* wchar_t* string * wchar_t* string