Use toLower() and toUpper()

This commit is contained in:
Olivier Teulière 2012-12-23 18:15:55 +01:00
parent b039d55c81
commit d55b3b2bdf
12 changed files with 28 additions and 52 deletions

View file

@ -22,7 +22,6 @@
#include "config.h"
#include <fstream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cerrno>
@ -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);

View file

@ -23,7 +23,6 @@
#include <cstring>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#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<wdstring> &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());

View file

@ -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>
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 <typename ScannerT>
@ -138,8 +137,7 @@ void evaluate(const Header &iHeader, iter_t const& i, stack<Node*> &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;

View file

@ -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;

View file

@ -21,8 +21,7 @@
#include <sstream>
#include <string>
#include <algorithm>
#include <wctype.h>
#include <cwctype>
#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);
}

View file

@ -19,8 +19,6 @@
*****************************************************************************/
#include <boost/foreach.hpp>
#include <algorithm> // For transform
#include <cwctype> // 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);
}

View file

@ -19,8 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <wctype.h>
#include <algorithm>
#include <cwctype>
#include <cstdio>
#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;
}

View file

@ -20,13 +20,13 @@
#include <boost/foreach.hpp>
#include <algorithm>
#include <wctype.h>
#include <sstream>
#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;

View file

@ -21,7 +21,6 @@
#include <string>
#include <sstream>
#include <algorithm> // For std::transform
#include <wctype.h>
#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;

View file

@ -19,9 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <algorithm>
#include <cwctype> // For towupper
#include "config.h"
#if ENABLE_NLS
# include <libintl.h>
@ -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);

View file

@ -22,7 +22,6 @@
#include <map>
#include <vector>
#include <algorithm>
#include <fstream>
#include <QtGui/QTreeView>
#include <QtGui/QStandardItemModel>
@ -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)
{

View file

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <algorithm> // For std::transform
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtCore/QSettings>
@ -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())