Moved String helper functions to service class

This commit is contained in:
Nav
2022-12-26 21:57:28 +00:00
parent 8fa7e82c56
commit 90ef72f686
5 changed files with 19 additions and 16 deletions

View File

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

View File

@@ -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<std::string>();
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<std::string>());
this->name = StringService::asciiToLower(targetNode["name"].as<std::string>());
if (targetNode["variantName"]) {
this->variantName = String::asciiToLower(targetNode["variantName"].as<std::string>());
this->variantName = StringService::asciiToLower(targetNode["variantName"].as<std::string>());
}
this->targetNode = targetNode;
@@ -146,7 +148,7 @@ namespace Bloom
throw Exceptions::InvalidConfig("No debug tool name found.");
}
this->name = String::asciiToLower(debugToolNode["name"].as<std::string>());
this->name = StringService::asciiToLower(debugToolNode["name"].as<std::string>());
if (debugToolNode["releasePostDebugSession"]) {
this->releasePostDebugSession = debugToolNode["releasePostDebugSession"].as<bool>(
@@ -162,7 +164,7 @@ namespace Bloom
throw Exceptions::InvalidConfig("No debug server name found.");
}
this->name = String::asciiToLower(debugServerNode["name"].as<std::string>());
this->name = StringService::asciiToLower(debugServerNode["name"].as<std::string>());
this->debugServerNode = debugServerNode;
}
}

View File

@@ -1,13 +1,13 @@
#include "String.hpp"
#include "StringService.hpp"
#include <algorithm>
#include <cctype>
#include <sstream>
#include <iomanip>
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;
});

View File

@@ -3,9 +3,9 @@
#include <string>
#include <vector>
namespace Bloom
namespace Bloom::Services
{
class String
class StringService
{
public:
static std::string asciiToLower(std::string str);

View File

@@ -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<std::string>());
const auto physicalInterfaceName = Services::StringService::asciiToLower(targetNode["physicalInterface"].as<std::string>());
const auto physicalInterfaceIt = Avr8TargetConfig::debugPhysicalInterfacesByConfigName.find(
physicalInterfaceName
);