String and YAML utilities
This commit is contained in:
@@ -7,6 +7,7 @@ target_sources(
|
|||||||
# Helpers & other
|
# Helpers & other
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Logger/Logger.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Logger/Logger.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/Paths.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/Paths.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/String.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EpollInstance.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EpollInstance.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EventFdNotifier.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EventFdNotifier.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/ConditionVariableNotifier.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/ConditionVariableNotifier.cpp
|
||||||
|
|||||||
29
src/Helpers/String.cpp
Normal file
29
src/Helpers/String.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "String.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
std::string String::asciiToLower(std::string str) {
|
||||||
|
std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) {
|
||||||
|
return std::tolower(character);
|
||||||
|
});
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string String::asciiToUpper(std::string str) {
|
||||||
|
std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) {
|
||||||
|
return std::toupper(character);
|
||||||
|
});
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool String::isAscii(const std::string& str) {
|
||||||
|
return !std::any_of(str.begin(), str.end(), [] (unsigned char character) {
|
||||||
|
return character > 127;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/Helpers/String.hpp
Normal file
16
src/Helpers/String.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
class String
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static std::string asciiToLower(std::string str);
|
||||||
|
|
||||||
|
static std::string asciiToUpper(std::string str);
|
||||||
|
|
||||||
|
static bool isAscii(const std::string& str);
|
||||||
|
};
|
||||||
|
}
|
||||||
21
src/Helpers/YamlUtilities.hpp
Normal file
21
src/Helpers/YamlUtilities.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
class YamlUtilities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename Type>
|
||||||
|
static bool isType(const YAML::Node& node) {
|
||||||
|
try {
|
||||||
|
node.as<Type>();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (YAML::BadConversion&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user