mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-30 09:08:35 +00:00
adding an utils struct
This commit is contained in:
+1
-1
@@ -147,7 +147,7 @@ set(SOURCES
|
||||
sources/Runner/LobbyScene.cpp
|
||||
sources/Runner/ResumeLobbyScene.cpp
|
||||
sources/Runner/ScoreScene.cpp
|
||||
sources/Parser/Node.cpp sources/Parser/Node.hpp)
|
||||
sources/Parser/Node.cpp sources/Parser/Node.hpp sources/Utils/Utils.cpp sources/Utils/Utils.hpp)
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
${SOURCES}
|
||||
|
||||
@@ -441,4 +441,19 @@ namespace BBM {
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
std::string ParserYAML::getHeader(const std::string &line)
|
||||
{
|
||||
std::stringstream ss(line);
|
||||
std::string headerName;
|
||||
std::string garbage;
|
||||
|
||||
ss >> headerName >> garbage;
|
||||
|
||||
|
||||
if (!garbage.empty()) {
|
||||
throw ParserError("error on getHeader line: ");
|
||||
}
|
||||
return headerName;
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,8 @@ namespace BBM {
|
||||
static bool _isFloat(const std::string &s);
|
||||
static std::vector<std::string> _splitStr(const std::string &str, char delim);
|
||||
|
||||
static std::string getHeader(const std::string &line);
|
||||
|
||||
public:
|
||||
//! @brief All name that was into the file
|
||||
static std::vector<std::string> playerName;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by cbihan on 17/06/2021.
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
inline void Utils::ltrim(std::string &s)
|
||||
{
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
}
|
||||
|
||||
inline void Utils::rtrim(std::string &s)
|
||||
{
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), s.end());
|
||||
}
|
||||
|
||||
inline void Utils::trim(std::string &s)
|
||||
{
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
inline std::string Utils::ltrim_copy(std::string s)
|
||||
{
|
||||
ltrim(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::string Utils::rtrim_copy(std::string s)
|
||||
{
|
||||
rtrim(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::string Utils::trim_copy(std::string s)
|
||||
{
|
||||
trim(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by cbihan on 17/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
struct Utils
|
||||
{
|
||||
//! @brief trim left end
|
||||
static inline void ltrim(std::string &s);
|
||||
|
||||
//! @brief trim right end
|
||||
static inline void rtrim(std::string &s);
|
||||
|
||||
//! @brief trim from both ends
|
||||
static inline void trim(std::string &s);
|
||||
|
||||
//! @brief trim left end (copying)
|
||||
static inline std::string ltrim_copy(std::string s);
|
||||
|
||||
//! @brief trim right end (copying)
|
||||
static inline std::string rtrim_copy(std::string s);
|
||||
|
||||
//! @brief trim from both ends (copying)
|
||||
static inline std::string trim_copy(std::string s);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user