mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
rework config management
* Add standard way to do str2val and val2str conversion * Add support for a config file * Add support for reading and writing settings via ioctl
This commit is contained in:
parent
8d989777f8
commit
54c41c4994
90 changed files with 3292 additions and 2619 deletions
47
src/str.cpp
47
src/str.cpp
|
|
@ -43,7 +43,25 @@ namespace str
|
|||
const string &str,
|
||||
const char delimiter)
|
||||
{
|
||||
return split(result,str.c_str(),delimiter);
|
||||
return str::split(result,str.c_str(),delimiter);
|
||||
}
|
||||
|
||||
void
|
||||
splitkv(const string &str_,
|
||||
const char delimiter_,
|
||||
string *key_,
|
||||
string *val_)
|
||||
{
|
||||
istringstream iss;
|
||||
std::string key;
|
||||
std::string val;
|
||||
|
||||
iss.str(str_);
|
||||
std::getline(iss,key,delimiter_);
|
||||
std::getline(iss,val,'\0');
|
||||
|
||||
*key_ = key;
|
||||
*val_ = val;
|
||||
}
|
||||
|
||||
string
|
||||
|
|
@ -149,8 +167,16 @@ namespace str
|
|||
}
|
||||
|
||||
bool
|
||||
ends_with(const string &str_,
|
||||
const string &suffix_)
|
||||
startswith(const string &str_,
|
||||
const string &prefix_)
|
||||
{
|
||||
return ((str_.size() >= prefix_.size()) &&
|
||||
(str_.compare(0,prefix_.size(),prefix_) == 0));
|
||||
}
|
||||
|
||||
bool
|
||||
endswith(const string &str_,
|
||||
const string &suffix_)
|
||||
{
|
||||
if(suffix_.size() > str_.size())
|
||||
return false;
|
||||
|
|
@ -159,4 +185,19 @@ namespace str
|
|||
suffix_.rend(),
|
||||
str_.rbegin());
|
||||
}
|
||||
|
||||
std::string
|
||||
trim(const std::string &str_)
|
||||
{
|
||||
std::string rv;
|
||||
|
||||
rv = str_;
|
||||
|
||||
while(!rv.empty() && (rv[0] == ' '))
|
||||
rv.erase(0);
|
||||
while(!rv.empty() && (rv[rv.size()-1] == ' '))
|
||||
rv.erase(rv.size()-1);
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue