From d55b3b2bdf01eaf08a89fc606d370a75ee476ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sun, 23 Dec 2012 18:15:55 +0100 Subject: [PATCH] Use toLower() and toUpper() --- dic/dic.cpp | 15 +++++---------- dic/dic_search.cpp | 7 ++----- dic/grammar.cpp | 8 +++----- dic/header.cpp | 4 +--- dic/tile.cpp | 10 +++++----- game/arbitration.cpp | 6 +----- game/board.cpp | 6 +++--- game/move.cpp | 5 ++--- game/round.cpp | 3 +-- game/training.cpp | 7 +------ qt/dic_tools_widget.cpp | 4 ++-- qt/tile_widget.cpp | 5 ++--- 12 files changed, 28 insertions(+), 52 deletions(-) diff --git a/dic/dic.cpp b/dic/dic.cpp index f27dd33..7bf3ccc 100644 --- a/dic/dic.cpp +++ b/dic/dic.cpp @@ -22,7 +22,6 @@ #include "config.h" #include -#include #include #include #include @@ -45,6 +44,7 @@ #include "header.h" #include "dic_exception.h" #include "dic_internals.h" +#include "encoding.h" #include "tile.h" @@ -81,14 +81,10 @@ Dictionary::Dictionary(const string &iPath) initializeTiles(); // Concatenate the uppercase and lowercase letters - wstring lower = m_header->getLetters(); - std::transform(lower.begin(), lower.end(), lower.begin(), towlower); - m_allLetters = m_header->getLetters() + lower; + m_allLetters = m_header->getLetters() + toLower(m_header->getLetters()); // Same for the input characters - lower = m_header->getInputChars(); - std::transform(lower.begin(), lower.end(), lower.begin(), towlower); - m_allInputChars = m_header->getInputChars() + lower; + m_allInputChars = m_header->getInputChars() + toLower(m_header->getInputChars()); // Build the cache for the convertToDisplay() and convertFromInput() // methods. @@ -100,10 +96,9 @@ Dictionary::Dictionary(const string &iPath) BOOST_FOREACH(wstring str, it->second) { // Make sure the string is in uppercase - std::transform(str.begin(), str.end(), str.begin(), towupper); + str = toUpper(str); // Make a lowercase copy - wstring lower = str; - std::transform(lower.begin(), lower.end(), lower.begin(), towlower); + wstring lower = toLower(str); // Fill the cache m_displayInputCache[towupper(it->first)].push_back(str); m_displayInputCache[towlower(it->first)].push_back(lower); diff --git a/dic/dic_search.cpp b/dic/dic_search.cpp index 71028cb..536d6b4 100644 --- a/dic/dic_search.cpp +++ b/dic/dic_search.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include "dic_internals.h" #include "dic_exception.h" @@ -233,8 +232,7 @@ void Dictionary::searchRacc(const wstring &iWord, // Transform the given word to make it suitable for display wdstring displayWord = convertToDisplay(iWord); // Make it uppercase - std::transform(displayWord.begin(), displayWord.end(), - displayWord.begin(), towupper); + displayWord = toUpper(displayWord); // Try to add a letter at the front const wstring &letters = getHeader().getLetters(); @@ -288,8 +286,7 @@ void Dictionary::searchBenj(const wstring &iWord, vector &oWordList, // Transform the given word to make it suitable for display wdstring displayWord = convertToDisplay(iWord); // Make it uppercase - std::transform(displayWord.begin(), displayWord.end(), - displayWord.begin(), towupper); + displayWord = toUpper(displayWord); const DicEdge *edge0, *edge1, *edge2, *edgetst; edge0 = getEdgeAt(getRoot()); diff --git a/dic/grammar.cpp b/dic/grammar.cpp index a16f50e..570bd38 100644 --- a/dic/grammar.cpp +++ b/dic/grammar.cpp @@ -31,6 +31,7 @@ #include "dic.h" #include "header.h" +#include "encoding.h" #include "regexp.h" using namespace boost::spirit::classic; @@ -54,9 +55,7 @@ struct RegexpGrammar : grammar RegexpGrammar(const wstring &letters) { - wstring lower = letters; - std::transform(lower.begin(), lower.end(), lower.begin(), towlower); - m_allLetters = letters + lower; + m_allLetters = letters + toLower(letters); } template @@ -138,8 +137,7 @@ void evaluate(const Header &iHeader, iter_t const& i, stack &evalStack, wstring choiceLetters(i->value.begin(), i->value.end()); // Make sure the letters are in upper case - std::transform(choiceLetters.begin(), choiceLetters.end(), - choiceLetters.begin(), towupper); + choiceLetters = toUpper(choiceLetters); // The dictionary letters are already in upper case const wstring &letters = iHeader.getLetters(); wstring::const_iterator itLetter; diff --git a/dic/header.cpp b/dic/header.cpp index f4100e5..cfb8b20 100644 --- a/dic/header.cpp +++ b/dic/header.cpp @@ -637,9 +637,7 @@ wstring Header::writeDisplayAndInput() const BOOST_FOREACH(const wstring &str, it->second) { // Make sure the string is uppercase - wstring upStr = str; - std::transform(upStr.begin(), upStr.end(), upStr.begin(), towupper); - serialized += L"|" + upStr; + serialized += L"|" + toUpper(str); } } return serialized; diff --git a/dic/tile.cpp b/dic/tile.cpp index a29f204..aae5995 100644 --- a/dic/tile.cpp +++ b/dic/tile.cpp @@ -21,8 +21,7 @@ #include #include -#include -#include +#include #include "tile.h" #include "header.h" #include "encoding.h" @@ -30,6 +29,9 @@ #include "debug.h" +using namespace std; + + INIT_LOGGER(dic, Tile); @@ -114,9 +116,7 @@ wstring Tile::getDisplayStr() const throw DicException("Tile::getDisplayStr: Invalid tile"); if (m_joker && iswalpha(m_char)) { - wstring str = m_header->getDisplayStr(m_code); - std::transform(str.begin(), str.end(), str.begin(), towlower); - return str; + return ::toLower(m_header->getDisplayStr(m_code)); } return m_header->getDisplayStr(m_code); } diff --git a/game/arbitration.cpp b/game/arbitration.cpp index 5e6f63f..e9049f2 100644 --- a/game/arbitration.cpp +++ b/game/arbitration.cpp @@ -19,8 +19,6 @@ *****************************************************************************/ #include -#include // For transform -#include // For towupper #include "arbitration.h" #include "rack.h" @@ -62,9 +60,7 @@ void Arbitration::setRackManual(const wstring &iLetters) // coming from user input. We do not consider a lowercase // letter to be a joker which has been assigned to a letter. // As a result, we simply make all the letters uppercase - wstring upperLetters = iLetters; - std::transform(upperLetters.begin(), upperLetters.end(), - upperLetters.begin(), towupper); + const wstring &upperLetters = toUpper(iLetters); const PlayedRack &newRack = helperSetRackManual(false, upperLetters); setGameAndPlayersRack(newRack); } diff --git a/game/board.cpp b/game/board.cpp index f14062d..c3a6699 100644 --- a/game/board.cpp +++ b/game/board.cpp @@ -19,8 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ -#include -#include +#include #include #include "dic.h" @@ -32,6 +31,7 @@ #include "round.h" #include "rack.h" #include "results.h" +#include "encoding.h" #include "debug.h" #define oo 0 @@ -129,7 +129,7 @@ wstring Board::getDisplayStr(int iRow, int iCol) const "Trying to get the display string on an empty board square"); wstring str = getTile(iRow, iCol).getDisplayStr(); if (isJoker(iRow, iCol)) - std::transform(str.begin(), str.end(), str.begin(), towlower); + str = toLower(str); return str; } diff --git a/game/move.cpp b/game/move.cpp index d2f725c..47d2275 100644 --- a/game/move.cpp +++ b/game/move.cpp @@ -20,13 +20,13 @@ #include -#include #include #include #include "move.h" #include "rack.h" #include "pldrack.h" +#include "encoding.h" #include "debug.h" @@ -60,8 +60,7 @@ Move::Move(const wstring &iLetters) : m_score(0), m_letters(iLetters) { // Make the letters uppercase - std::transform(m_letters.begin(), m_letters.end(), - m_letters.begin(), towupper); + m_letters = toUpper(m_letters); if (m_letters.empty()) m_type = PASS; diff --git a/game/round.cpp b/game/round.cpp index f4182d9..7e02da7 100644 --- a/game/round.cpp +++ b/game/round.cpp @@ -21,7 +21,6 @@ #include #include -#include // For std::transform #include #include "tile.h" #include "round.h" @@ -124,7 +123,7 @@ wstring Round::getWord() const { wstring chr = getTile(i).getDisplayStr(); if (isJoker(i)) - std::transform(chr.begin(), chr.end(), chr.begin(), towlower); + chr = toLower(chr); s += chr; } return s; diff --git a/game/training.cpp b/game/training.cpp index ac1b997..0a38ad2 100644 --- a/game/training.cpp +++ b/game/training.cpp @@ -19,9 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ -#include -#include // For towupper - #include "config.h" #if ENABLE_NLS # include @@ -77,9 +74,7 @@ void Training::setRackManual(bool iCheck, const wstring &iLetters) // coming from user input. We do not consider a lowercase // letter to be a joker which has been assigned to a letter. // As a result, we simply make all the letters uppercase - wstring upperLetters = iLetters; - std::transform(upperLetters.begin(), upperLetters.end(), - upperLetters.begin(), towupper); + wstring upperLetters = toUpper(iLetters); const PlayedRack &newRack = helperSetRackManual(iCheck, upperLetters); Command *pCmd1 = new GameRackCmd(*this, newRack); pCmd1->setHumanIndependent(false); diff --git a/qt/dic_tools_widget.cpp b/qt/dic_tools_widget.cpp index 4eef9bd..dada39a 100644 --- a/qt/dic_tools_widget.cpp +++ b/qt/dic_tools_widget.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -39,6 +38,7 @@ #include "dic.h" #include "header.h" #include "listdic.h" +#include "encoding.h" #include "dic_exception.h" using namespace std; @@ -169,7 +169,7 @@ void DicToolsWidget::refreshCheck() wstring input = m_dic->convertFromInput(wfq(rack->text())); bool res = m_dic->searchWord(input); // Convert the input to uppercase - std::transform(input.begin(), input.end(), input.begin(), towupper); + input = toUpper(input); const wdstring &dispStr = m_dic->convertToDisplay(input); if (res) { diff --git a/qt/tile_widget.cpp b/qt/tile_widget.cpp index 5fb7e15..37fe799 100644 --- a/qt/tile_widget.cpp +++ b/qt/tile_widget.cpp @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ -#include // For std::transform #include #include #include @@ -27,6 +26,7 @@ #include "prefs_dialog.h" #include "qtcommon.h" #include "tile.h" +#include "encoding.h" using namespace std; @@ -181,9 +181,8 @@ void TileWidget::paintEvent(QPaintEvent *iEvent) // Draw the letter if (!m_tile.isEmpty()) { - wstring chr = m_tile.getDisplayStr(); + wstring chr = toUpper(m_tile.getDisplayStr()); // Make the display char in upper case - std::transform(chr.begin(), chr.end(), chr.begin(), towupper); painter.setPen(m_isJoker ? TextJokerColour : TextNormalColour); painter.setFont(letterFont); if (!m_tile.isPureJoker())