From b039d55c814324cc9a8477d9ff70c933105e68a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sat, 22 Dec 2012 00:52:20 +0100 Subject: [PATCH] New utility functions: toUpper() and toLower() --- dic/encoding.cpp | 17 +++++++++++++++++ dic/encoding.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/dic/encoding.cpp b/dic/encoding.cpp index 8ad04f5..a10e036 100644 --- a/dic/encoding.cpp +++ b/dic/encoding.cpp @@ -20,6 +20,7 @@ #include "config.h" +#include #include #include #include @@ -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, const char *iBuffer, unsigned int iBufSize, const string &iContext) diff --git a/dic/encoding.h b/dic/encoding.h index d1df327..efc70f3 100644 --- a/dic/encoding.h +++ b/dic/encoding.h @@ -83,6 +83,16 @@ string padAndConvert(const wstring &iWstr, unsigned int iLength, string centerAndConvert(const wstring &iWstr, unsigned int iLength, 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 * wchar_t* string