Skip to content

Commit

Permalink
Replace boost case conversion routines.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 18, 2017
1 parent 009787f commit 4309993
Show file tree
Hide file tree
Showing 46 changed files with 159 additions and 110 deletions.
1 change: 0 additions & 1 deletion include/precompiled_boost.h
Expand Up @@ -10,5 +10,4 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include "util/Noncopyable.h"
56 changes: 56 additions & 0 deletions libs/string/case_conv.h
@@ -0,0 +1,56 @@
#pragma once

#include <string>
#include <algorithm>
#include <cctype>

namespace string
{

/**
* Converts the given input string to lowercase, using the
* C-function tolower(). The string is modified in-place.
*/
inline void to_lower(std::string& input)
{
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
}

/**
* Converts the given input string to lowercase, using the
* C-function tolower(), and returns a copy of the result.
*/
inline std::string to_lower_copy(const std::string& input)
{
std::string output;
output.resize(input.size());

std::transform(input.begin(), input.end(), output.begin(), ::tolower);

return output;
}

/**
* Converts the given input string to uppercase, using the
* C-function toupper(). The string is modified in-place.
*/
inline void to_upper(std::string& input)
{
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
}

/**
* Converts the given input string to uppercase, using the
* C-function tolower(), and returns a copy of the result.
*/
inline std::string to_upper_copy(const std::string& input)
{
std::string output;
output.resize(input.size());

std::transform(input.begin(), input.end(), output.begin(), ::toupper);

return output;
}

}
4 changes: 2 additions & 2 deletions libs/wxutil/FileChooser.cpp
Expand Up @@ -11,7 +11,7 @@
#include "MultiMonitor.h"
#include "dialog/MessageBox.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include <wx/app.h>

namespace wxutil
Expand Down Expand Up @@ -59,7 +59,7 @@ void FileChooser::construct()
}

// Make default extension lowercase
boost::algorithm::to_lower(_defaultExt);
string::to_lower(_defaultExt);

int defaultFormatIdx = 0;
int curFormatIdx = 0;
Expand Down
2 changes: 0 additions & 2 deletions libs/wxutil/preview/ModelPreview.cpp
Expand Up @@ -18,8 +18,6 @@

#include "iuimanager.h"

#include <boost/algorithm/string/case_conv.hpp>

namespace wxutil
{

Expand Down
1 change: 0 additions & 1 deletion libs/wxutil/preview/ParticlePreview.cpp
Expand Up @@ -20,7 +20,6 @@

#include <fmt/format.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>

Expand Down
1 change: 0 additions & 1 deletion plugins/dm.conversation/ConversationKeyExtractor.cpp
Expand Up @@ -4,7 +4,6 @@

#include <boost/lexical_cast.hpp>
#include <regex>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/classification.hpp>
Expand Down
6 changes: 3 additions & 3 deletions plugins/dm.gui/gui/GuiScript.cpp
Expand Up @@ -4,7 +4,7 @@
#include "parser/DefTokeniser.h"
#include "Gui.h"

#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -223,7 +223,7 @@ void GuiScript::switchOnToken(const std::string& token, parser::DefTokeniser& to
while (tokeniser.hasMoreTokens() && _curLevel == blockLevel)
{
std::string nextToken = tokeniser.nextToken();
boost::algorithm::to_lower(nextToken);
string::to_lower(nextToken);

switchOnToken(nextToken, tokeniser);
}
Expand Down Expand Up @@ -291,7 +291,7 @@ void GuiScript::parseStatement(parser::DefTokeniser& tokeniser)
}

std::string token = tokeniser.nextToken();
boost::algorithm::to_lower(token);
string::to_lower(token);

switchOnToken(token, tokeniser);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/dm.gui/gui/GuiWindowDef.cpp
Expand Up @@ -8,7 +8,7 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include "string/replace.h"

#include "GuiScript.h"
Expand Down Expand Up @@ -154,7 +154,7 @@ void GuiWindowDef::constructFromTokens(parser::DefTokeniser& tokeniser)
while (tokeniser.hasMoreTokens())
{
std::string token = tokeniser.nextToken();
boost::algorithm::to_lower(token);
string::to_lower(token);

if (token == "rect")
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/dm.gui/gui/Variable.cpp
Expand Up @@ -2,15 +2,15 @@

#include "Gui.h"
#include "GuiWindowDef.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"

namespace gui
{

WindowDefVariable::WindowDefVariable(GuiWindowDef& windowDef,
const std::string& name) :
_windowDef(windowDef),
_name(boost::algorithm::to_lower_copy(name))
_name(string::to_lower_copy(name))
{}

// Assign a value to this Variable (returns TRUE on success)
Expand Down
4 changes: 2 additions & 2 deletions plugins/dm.objectives/Component.cpp
@@ -1,7 +1,7 @@
#include "Component.h"

#include "string/convert.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include "string/replace.h"

namespace objectives {
Expand Down Expand Up @@ -128,7 +128,7 @@ std::string Component::getString() {
// Convert the first character of the sentence to upper case
if (!sentence.empty()) {
std::string c(sentence.begin(), sentence.begin()+1);
sentence[0] = boost::algorithm::to_upper_copy(c)[0];
sentence[0] = string::to_upper_copy(c)[0];

// Append a full stop at the end of the sentence
if (sentence[sentence.length() - 1] != '.') {
Expand Down
1 change: 0 additions & 1 deletion plugins/dm.objectives/ObjectiveKeyExtractor.cpp
Expand Up @@ -4,7 +4,6 @@

#include <boost/lexical_cast.hpp>
#include <regex>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/classification.hpp>
Expand Down
1 change: 0 additions & 1 deletion plugins/eclassmgr/Doom3EntityClass.cpp
Expand Up @@ -5,7 +5,6 @@
#include "os/path.h"
#include "string/convert.h"

#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <fmt/format.h>
Expand Down
10 changes: 5 additions & 5 deletions plugins/eclassmgr/EClassManager.cpp
Expand Up @@ -15,7 +15,7 @@
#include "Doom3EntityClass.h"
#include "Doom3ModelDef.h"

#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include <functional>

#include "debugging/ScopedDebugTimer.h"
Expand Down Expand Up @@ -46,7 +46,7 @@ IEntityClassPtr EClassManager::findOrInsert(const std::string& name, bool has_br
}

// Convert string to lowercase, for case-insensitive lookup
std::string lName = boost::algorithm::to_lower_copy(name);
std::string lName = string::to_lower_copy(name);

// Find and return if exists
Doom3EntityClassPtr eclass = findInternal(lName);
Expand Down Expand Up @@ -218,7 +218,7 @@ IEntityClassPtr EClassManager::findClass(const std::string& className)
ensureDefsLoaded();

// greebo: Convert the lookup className string to lowercase first
std::string classNameLower = boost::algorithm::to_lower_copy(className);
std::string classNameLower = string::to_lower_copy(className);

EntityClasses::const_iterator i = _entityClasses.find(classNameLower);

Expand Down Expand Up @@ -353,13 +353,13 @@ void EClassManager::parse(TextInputStream& inStr, const std::string& modDir)
while (tokeniser.hasMoreTokens())
{
std::string blockType = tokeniser.nextToken();
boost::algorithm::to_lower(blockType);
string::to_lower(blockType);

if (blockType == "entitydef")
{
// Get the (lowercase) entity name
const std::string sName =
boost::algorithm::to_lower_copy(tokeniser.nextToken());
string::to_lower_copy(tokeniser.nextToken());

// Ensure that an Entity class with this name already exists
// When reloading entityDef declarations, most names will already be registered
Expand Down
1 change: 0 additions & 1 deletion plugins/entity/Doom3Entity.cpp
Expand Up @@ -3,7 +3,6 @@
#include "iradiant.h"
#include "ieclass.h"
#include "debugging/debugging.h"
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <functional>

Expand Down
4 changes: 2 additions & 2 deletions plugins/eventmanager/Accelerator.cpp
Expand Up @@ -4,7 +4,7 @@
#include <cctype>
#include <wx/defs.h>
#include "wxutil/Modifier.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"

namespace ui
{
Expand Down Expand Up @@ -108,7 +108,7 @@ unsigned int Accelerator::getKeyCodeFromName(const std::string& name)
}
else // words like TAB, ESCAPE, etc.
{
std::string upper = boost::algorithm::to_upper_copy(name);
std::string upper = string::to_upper_copy(name);

// These are compatible with the ones defined in gdkkeysyms.h
// to be able to load legacy input.xml files
Expand Down
10 changes: 5 additions & 5 deletions plugins/filetypes/FileTypeRegistry.cpp
Expand Up @@ -6,7 +6,7 @@
#include "debugging/debugging.h"

#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"

FileTypeRegistry::FileTypeRegistry()
{
Expand All @@ -16,7 +16,7 @@ FileTypeRegistry::FileTypeRegistry()
void FileTypeRegistry::registerPattern(const std::string& fileType, const FileTypePattern& pattern)
{
// Convert the file extension to lowercase
std::string fileTypeLower = boost::algorithm::to_lower_copy(fileType);
std::string fileTypeLower = string::to_lower_copy(fileType);

// Find or insert the fileType into the map
FileTypes::iterator i = _fileTypes.find(fileTypeLower);
Expand All @@ -32,8 +32,8 @@ void FileTypeRegistry::registerPattern(const std::string& fileType, const FileTy

// Ensure the pattern contains a lowercase extension
FileTypePattern patternLocal = pattern;
boost::algorithm::to_lower(patternLocal.extension);
boost::algorithm::to_lower(patternLocal.pattern);
string::to_lower(patternLocal.extension);
string::to_lower(patternLocal.pattern);

// Check if the pattern is already associated
for (const FileTypePattern& pattern : patternList)
Expand All @@ -52,7 +52,7 @@ void FileTypeRegistry::registerPattern(const std::string& fileType, const FileTy
FileTypePatterns FileTypeRegistry::getPatternsForType(const std::string& fileType)
{
// Convert the file extension to lowercase and try to find the matching list
FileTypes::const_iterator i = _fileTypes.find(boost::algorithm::to_lower_copy(fileType));
FileTypes::const_iterator i = _fileTypes.find(string::to_lower_copy(fileType));

return i != _fileTypes.end() ? i->second : FileTypePatterns();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/fonts/GlyphInfo.cpp
Expand Up @@ -2,7 +2,7 @@

#include "GlyphInfo.h"
#include "os/file.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include "string/replace.h"

namespace fonts
Expand All @@ -23,7 +23,7 @@ GlyphInfo::GlyphInfo(const q3font::Q3GlyphInfo& q3glyph)
t2 = q3glyph.t2;

texture = q3glyph.shaderName;
boost::algorithm::to_lower(texture);
string::to_lower(texture);

// Cut off fonts/
string::replace_first(texture, "fonts/", "");
Expand Down
8 changes: 4 additions & 4 deletions plugins/image/Doom3ImageLoader.cpp
Expand Up @@ -8,7 +8,7 @@
#include "iregistry.h"
#include "igame.h"

#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

Expand Down Expand Up @@ -39,7 +39,7 @@ ImageTypeLoader::Extensions getGameFileImageExtensions()
{
// Get the file extension
std::string extension = i->getContent();
boost::algorithm::to_lower(extension);
string::to_lower(extension);
_extensions.push_back(extension);
}
}
Expand All @@ -54,7 +54,7 @@ void Doom3ImageLoader::addLoaderToMap(ImageTypeLoader::Ptr loader)
ImageTypeLoader::Extensions exts = loader->getExtensions();
for (auto i = exts.begin(); i != exts.end(); ++i)
{
_loadersByExtension[boost::algorithm::to_lower_copy(*i)] = loader;
_loadersByExtension[string::to_lower_copy(*i)] = loader;
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ ImagePtr Doom3ImageLoader::imageFromFile(const std::string& filename) const

if (!file->failed())
{
const std::string ext = boost::algorithm::to_lower_copy(
const std::string ext = string::to_lower_copy(
os::getExtension(filename)
);

Expand Down
6 changes: 3 additions & 3 deletions plugins/model/PicoModelLoader.cpp
Expand Up @@ -11,7 +11,7 @@
#include "PicoModelNode.h"

#include "idatastream.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "string/case_conv.h"

namespace model {

Expand All @@ -30,7 +30,7 @@ namespace {

PicoModelLoader::PicoModelLoader(const picoModule_t* module, const std::string& extension) :
_module(module),
_extension(boost::algorithm::to_upper_copy(extension))
_extension(string::to_upper_copy(extension))
{}

const std::string& PicoModelLoader::getExtension() const
Expand Down Expand Up @@ -87,7 +87,7 @@ IModelPtr PicoModelLoader::loadModelFromPath(const std::string& name)

// Determine the file extension (ASE or LWO) to pass down to the PicoModel
std::string fName = file->getName();
boost::algorithm::to_lower(fName);
string::to_lower(fName);
std::string fExt = fName.substr(fName.size() - 3, 3);

picoModel_t* model = PicoModuleLoadModelStream(
Expand Down

0 comments on commit 4309993

Please sign in to comment.