From 90ef72f686d306f4856e6f13d1a626580293e5de Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 26 Dec 2022 21:57:28 +0000 Subject: [PATCH] Moved String helper functions to service class --- src/CMakeLists.txt | 2 +- src/ProjectConfig.cpp | 14 ++++++++------ .../String.cpp => Services/StringService.cpp} | 10 +++++----- .../String.hpp => Services/StringService.hpp} | 4 ++-- .../Microchip/AVR/AVR8/Avr8TargetConfig.cpp | 5 +++-- 5 files changed, 19 insertions(+), 16 deletions(-) rename src/{Helpers/String.cpp => Services/StringService.cpp} (85%) rename src/{Helpers/String.hpp => Services/StringService.hpp} (89%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 06549cfa..8a4221df 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,10 +8,10 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/Services/TargetControllerService.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Services/PathService.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Services/ProcessService.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Services/StringService.cpp # Helpers & other ${CMAKE_CURRENT_SOURCE_DIR}/Logger/Logger.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Helpers/String.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EpollInstance.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EventFdNotifier.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Helpers/ConditionVariableNotifier.cpp diff --git a/src/ProjectConfig.cpp b/src/ProjectConfig.cpp index f5adb2ad..a3660518 100644 --- a/src/ProjectConfig.cpp +++ b/src/ProjectConfig.cpp @@ -1,11 +1,13 @@ #include "ProjectConfig.hpp" -#include "src/Helpers/String.hpp" +#include "src/Services/StringService.hpp" #include "src/Logger/Logger.hpp" #include "src/Exceptions/InvalidConfig.hpp" namespace Bloom { + using Services::StringService; + ProjectConfig::ProjectConfig(const YAML::Node& configNode) { if (!configNode["environments"]) { throw Exceptions::InvalidConfig( @@ -28,7 +30,7 @@ namespace Bloom try { environmentName = environmentIt->first.as(); - if (!String::isAscii(environmentName.value())) { + if (!StringService::isAscii(environmentName.value())) { throw Exceptions::InvalidConfig( "Environment name ('" + environmentName.value() + "') is not in ASCII form." ); @@ -132,10 +134,10 @@ namespace Bloom throw Exceptions::InvalidConfig("No target name found."); } - this->name = String::asciiToLower(targetNode["name"].as()); + this->name = StringService::asciiToLower(targetNode["name"].as()); if (targetNode["variantName"]) { - this->variantName = String::asciiToLower(targetNode["variantName"].as()); + this->variantName = StringService::asciiToLower(targetNode["variantName"].as()); } this->targetNode = targetNode; @@ -146,7 +148,7 @@ namespace Bloom throw Exceptions::InvalidConfig("No debug tool name found."); } - this->name = String::asciiToLower(debugToolNode["name"].as()); + this->name = StringService::asciiToLower(debugToolNode["name"].as()); if (debugToolNode["releasePostDebugSession"]) { this->releasePostDebugSession = debugToolNode["releasePostDebugSession"].as( @@ -162,7 +164,7 @@ namespace Bloom throw Exceptions::InvalidConfig("No debug server name found."); } - this->name = String::asciiToLower(debugServerNode["name"].as()); + this->name = StringService::asciiToLower(debugServerNode["name"].as()); this->debugServerNode = debugServerNode; } } diff --git a/src/Helpers/String.cpp b/src/Services/StringService.cpp similarity index 85% rename from src/Helpers/String.cpp rename to src/Services/StringService.cpp index 3b3fd496..f2ed3f2f 100644 --- a/src/Helpers/String.cpp +++ b/src/Services/StringService.cpp @@ -1,13 +1,13 @@ -#include "String.hpp" +#include "StringService.hpp" #include #include #include #include -namespace Bloom +namespace Bloom::Services { - std::string String::asciiToLower(std::string str) { + std::string StringService::asciiToLower(std::string str) { std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) { return std::tolower(character); }); @@ -15,7 +15,7 @@ namespace Bloom return str; } - std::string String::asciiToUpper(std::string str) { + std::string StringService::asciiToUpper(std::string str) { std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) { return std::toupper(character); }); @@ -23,7 +23,7 @@ namespace Bloom return str; } - bool String::isAscii(const std::string& str) { + bool StringService::isAscii(const std::string& str) { return !std::any_of(str.begin(), str.end(), [] (unsigned char character) { return character > 127; }); diff --git a/src/Helpers/String.hpp b/src/Services/StringService.hpp similarity index 89% rename from src/Helpers/String.hpp rename to src/Services/StringService.hpp index 44b330d6..ee805a0f 100644 --- a/src/Helpers/String.hpp +++ b/src/Services/StringService.hpp @@ -3,9 +3,9 @@ #include #include -namespace Bloom +namespace Bloom::Services { - class String + class StringService { public: static std::string asciiToLower(std::string str); diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp index 7f58f669..841c1ea2 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp @@ -1,7 +1,8 @@ #include "Avr8TargetConfig.hpp" -#include "src/Helpers/String.hpp" #include "src/Services/PathService.hpp" +#include "src/Services/StringService.hpp" + #include "src/Exceptions/InvalidConfig.hpp" namespace Bloom::Targets::Microchip::Avr::Avr8Bit @@ -17,7 +18,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit throw InvalidConfig("Missing physical interface config parameter for AVR8 target."); } - const auto physicalInterfaceName = String::asciiToLower(targetNode["physicalInterface"].as()); + const auto physicalInterfaceName = Services::StringService::asciiToLower(targetNode["physicalInterface"].as()); const auto physicalInterfaceIt = Avr8TargetConfig::debugPhysicalInterfacesByConfigName.find( physicalInterfaceName );