just some thoughts
This commit is contained in:
parent
03d7614673
commit
f0d205dee7
15 changed files with 172 additions and 34 deletions
|
@ -4,12 +4,18 @@
|
|||
#include "helpers.h"
|
||||
|
||||
#include "iostream"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
static bool installed = false;
|
||||
static std::filesystem::path sPath;
|
||||
|
||||
bool isSpace(char ch){
|
||||
return std::isspace(static_cast<unsigned char>(ch));
|
||||
}
|
||||
|
||||
void setAbsoluteSharedPath () {
|
||||
installed = true;
|
||||
sPath = FULL_DATA_DIR "/" PROJECT_NAME; // should be something like /usr/share/pica or /local/usr/share/pica
|
||||
|
@ -36,7 +42,7 @@ void initPaths(const char* programPath) {
|
|||
if (endsWith(parent.string(), BIN_DIR)) { //this is the case when the program is installed somewhere but not system root
|
||||
std::filesystem::path bin(BIN_DIR); //so it will read from something like ../share/pica/ relative to the binary
|
||||
for (const auto& hop : bin) {
|
||||
(void)hop; //I do this just to make as many ups as many members are in bin
|
||||
UNUSED(hop); //I do this just to make as many ups as many members are in bin
|
||||
parent = parent.parent_path();
|
||||
}
|
||||
sPath = parent / DATA_DIR / PROJECT_NAME;
|
||||
|
@ -59,3 +65,40 @@ bool endsWith(const std::string& string, const std::string& query) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ltrim(std::string& string) {
|
||||
string.erase(
|
||||
string.begin(),
|
||||
std::find_if(
|
||||
string.begin(),
|
||||
string.end(),
|
||||
std::not_fn(isSpace)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void rtrim(std::string& string) {
|
||||
string.erase(
|
||||
std::find_if(
|
||||
string.rbegin(),
|
||||
string.rend(),
|
||||
std::not_fn(isSpace)
|
||||
).base(),
|
||||
string.end()
|
||||
);
|
||||
}
|
||||
|
||||
void trim(std::string& string) {
|
||||
ltrim(string);
|
||||
rtrim(string);
|
||||
}
|
||||
|
||||
std::string extract(std::string& string, std::string::size_type begin, std::string::size_type end) {
|
||||
std::string result = string.substr(begin, end);
|
||||
if (end == std::string::npos)
|
||||
string.erase(begin, end);
|
||||
else
|
||||
string.erase(begin, result.length() + 1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#define UNUSED(variable) (void)variable
|
||||
|
||||
void initPaths(const char* programPath);
|
||||
const std::filesystem::path& sharedPath();
|
||||
bool endsWith(const std::string& string, const std::string& query);
|
||||
|
||||
void ltrim(std::string& string);
|
||||
void rtrim(std::string& string);
|
||||
void trim(std::string& string);
|
||||
std::string extract(std::string& string, std::string::size_type begin, std::string::size_type end);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue