Replaced boost::trim functions with new Trim functions

Changes based on f0f6f61cab
dev
Tomasz Kapuściński 2023-08-09 20:11:08 +02:00
parent 32fb105bca
commit ecb789d059
9 changed files with 45 additions and 21 deletions

View File

@ -35,7 +35,6 @@
#include <algorithm>
#include <filesystem>
#include <map>
#include <boost/algorithm/string.hpp>
CModManager::CModManager(CApplication* app, CPathManager* pathManager)
: m_app{app},

View File

@ -32,8 +32,6 @@
#include "common/system/system_windows.h"
#endif
#include <boost/algorithm/string.hpp>
#include <filesystem>
CPathManager::CPathManager(CSystemUtils* systemUtils)

View File

@ -84,6 +84,26 @@ std::string StrUtils::Replace(const std::string &str, const std::string &oldStr,
return result;
}
void StrUtils::TrimLeft(std::string& s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
}
void StrUtils::TrimRight(std::string& s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
void StrUtils::Trim(std::string& str)
{
TrimLeft(str);
TrimRight(str);
}
std::string StrUtils::UnicodeCharToUtf8(unsigned int ch)
{
std::string result;

View File

@ -68,6 +68,14 @@ std::string Format(const char *fmt, ...);
//! Returns a string with every occurence of \a oldStr in \a str replaced to \a newStr
std::string Replace(const std::string &str, const std::string &oldStr, const std::string &newStr);
//! Remove whitespace from the beginning of the given string (in place)
void TrimLeft(std::string& str);
//! Remove whitespace from the end of the given string (in place)
void TrimRight(std::string& str);
//! Remove whitespace from both ends of the given string (in place)
void Trim(std::string& str);
//! Converts a wide Unicode char to a single UTF-8 encoded char
std::string UnicodeCharToUtf8(unsigned int ch);

View File

@ -20,13 +20,12 @@
#include "graphics/model/model_mod.h"
#include "common/ioutils.h"
#include "common/stringutils.h"
#include "common/resources/inputstream.h"
#include "graphics/model/model_io_exception.h"
#include "graphics/model/model_io_structs.h"
#include <boost/algorithm/string.hpp>
#include <array>
#include <iostream>
@ -279,8 +278,10 @@ ModelLODLevel MinMaxToLodLevel(float min, float max)
void ConvertOldTex1Name(ModelTriangle& triangle, const char* tex1Name)
{
triangle.material.albedoTexture = tex1Name;
boost::replace_all(triangle.material.albedoTexture, "bmp", "png");
boost::replace_all(triangle.material.albedoTexture, "tga", "png");
triangle.material.albedoTexture = StrUtils::Replace(
triangle.material.albedoTexture, "bmp", "png");
triangle.material.albedoTexture = StrUtils::Replace(
triangle.material.albedoTexture, "tga", "png");
}
void ConvertFromOldRenderState(ModelTriangle& triangle, int state)

View File

@ -20,6 +20,7 @@
#include "graphics/model/model_mod.h"
#include "common/ioutils.h"
#include "common/stringutils.h"
#include "common/resources/inputstream.h"
#include "graphics/model/model_io_exception.h"
@ -255,7 +256,7 @@ std::string ReadLineString(std::istream& stream, const std::string& expectedPref
throw CModelIOException("Unexpected EOF");
std::getline(stream, line);
boost::trim_right(line);
StrUtils::TrimRight(line);
if (!line.empty() && line[0] != '#')
break;
}
@ -270,7 +271,7 @@ std::string ReadLineString(std::istream& stream, const std::string& expectedPref
std::string value;
std::getline(s, value);
boost::trim_left(value);
StrUtils::TrimLeft(value);
return value;
}

View File

@ -38,7 +38,6 @@
#include <set>
#include <regex>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/replace.hpp>
CLevelParser::CLevelParser()
@ -190,14 +189,14 @@ void CLevelParser::Load()
}
}
boost::algorithm::trim(line);
StrUtils::Trim(line);
pos = line.find_first_of(" \t\n");
std::string command = line.substr(0, pos);
if (pos != std::string::npos)
{
line = line.substr(pos + 1);
boost::algorithm::trim(line);
StrUtils::Trim(line);
}
else
{
@ -246,9 +245,9 @@ void CLevelParser::Load()
{
pos = line.find_first_of("=");
std::string paramName = line.substr(0, pos);
boost::algorithm::trim(paramName);
StrUtils::Trim(paramName);
line = line.substr(pos + 1);
boost::algorithm::trim(line);
StrUtils::Trim(line);
if (line[0] == '\"')
{
@ -277,14 +276,14 @@ void CLevelParser::Load()
}
}
std::string paramValue = line.substr(0, pos + 1);
boost::algorithm::trim(paramValue);
StrUtils::Trim(paramValue);
parserLine->AddParam(paramName, std::make_unique<CLevelParserParam>(paramName, paramValue));
if (pos == std::string::npos)
break;
line = line.substr(pos + 1);
boost::algorithm::trim(line);
StrUtils::Trim(line);
}
if (parserLine->GetCommand().length() > 1 && parserLine->GetCommand()[0] == '#')

View File

@ -1115,7 +1115,7 @@ void CLevelParserParam::ParseArray()
int i = 0;
for (auto& value : values)
{
boost::algorithm::trim(value);
StrUtils::Trim(value);
if (value.empty()) continue;
auto param = std::make_unique<CLevelParserParam>(m_name + "[" + StrUtils::ToString(i) + "]", value);
param->SetLine(m_line);

View File

@ -40,8 +40,6 @@
#include "ui/controls/list.h"
#include "ui/controls/window.h"
#include <boost/algorithm/string/trim.hpp>
namespace Ui
{
@ -247,7 +245,7 @@ void CScreenPlayerSelect::UpdateNameControl()
total = pl->GetTotal();
sel = pl->GetSelect();
name = pe->GetText(100);
boost::trim(name);
StrUtils::Trim(name);
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NDELETE));
if ( pb != nullptr )
@ -382,7 +380,7 @@ bool CScreenPlayerSelect::NameCreate()
std::string name;
name = pe->GetText(100);
boost::trim(name);
StrUtils::Trim(name);
if ( name.empty() )
{
m_sound->Play(SOUND_TZOING);