From ca3a58934534fad5ebad38ca98ecb1f6c65f5560 Mon Sep 17 00:00:00 2001 From: codereader Date: Tue, 17 Oct 2017 19:39:07 +0200 Subject: [PATCH] Add replacements for boost::algorithm::replace_all[_copy]. --- libs/string/replace.h | 42 +++++++++++++++++++++++++++++++++ radiant/log/Console.cpp | 1 - radiant/log/PIDFile.h | 6 ++--- tools/msvc/libs.vcxproj | 1 + tools/msvc/libs.vcxproj.filters | 3 +++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 libs/string/replace.h diff --git a/libs/string/replace.h b/libs/string/replace.h new file mode 100644 index 0000000000..6653602e46 --- /dev/null +++ b/libs/string/replace.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +namespace string +{ + +/** + * Replaces all occurrences of the given search string in the subject + * with the given replacement, in-place. + */ +inline void replace_all(std::string& subject, const std::string& search, const std::string& replacement) +{ + std::size_t pos = 0; + + while ((pos = subject.find(search, pos)) != std::string::npos) + { + subject.replace(pos, search.length(), replacement); + pos += replacement.length(); + } +} + +/** + * Replaces all occurrences of of the given search string with + * the given replacement and returns a new string instance + * containing the result. The incoming subject is passed by value such + * that the original string is not altered. + */ +inline std::string replace_all_copy(std::string subject, const std::string& search, const std::string& replacement) +{ + std::size_t pos = 0; + + while ((pos = subject.find(search, pos)) != std::string::npos) + { + subject.replace(pos, search.length(), replacement); + pos += replacement.length(); + } + + return subject; +} + +} diff --git a/radiant/log/Console.cpp b/radiant/log/Console.cpp index 2909307e40..8be3480b30 100644 --- a/radiant/log/Console.cpp +++ b/radiant/log/Console.cpp @@ -11,7 +11,6 @@ #include "StringLogDevice.h" #include -#include namespace ui { diff --git a/radiant/log/PIDFile.h b/radiant/log/PIDFile.h index 30e697077a..06f835b136 100644 --- a/radiant/log/PIDFile.h +++ b/radiant/log/PIDFile.h @@ -5,7 +5,7 @@ #include "modulesystem/ModuleRegistry.h" #include "os/file.h" -#include +#include "string/replace.h" #define PID_FILENAME "darkradiant.pid" @@ -39,8 +39,8 @@ class PIDFile fs::path path = registry.getApplicationContext().getSettingsPath(); path /= "darkradiant.log"; std::string logPath = path.string(); - boost::algorithm::replace_all(logPath, "\\\\", "\\"); - boost::algorithm::replace_all(logPath, "//", "/"); + string::replace_all(logPath, "\\\\", "\\"); + string::replace_all(logPath, "//", "/"); std::string msg("Radiant failed to start properly the last time it was run.\n"); msg += "If this is happening again, you might want to check the log file in\n"; diff --git a/tools/msvc/libs.vcxproj b/tools/msvc/libs.vcxproj index 3f695e9d8c..c65adb6f5b 100644 --- a/tools/msvc/libs.vcxproj +++ b/tools/msvc/libs.vcxproj @@ -200,6 +200,7 @@ + diff --git a/tools/msvc/libs.vcxproj.filters b/tools/msvc/libs.vcxproj.filters index 8e782e8114..951d2076d2 100644 --- a/tools/msvc/libs.vcxproj.filters +++ b/tools/msvc/libs.vcxproj.filters @@ -160,6 +160,9 @@ util + + string +