Browse Source

Merge pull request #39 from trapexit/truncate_mount_list

remove longest common prefix from fsname. closes #38
pull/44/head
Antonio SJ Musumeci 10 years ago
parent
commit
233c216e66
  1. 4
      src/option_parser.cpp
  2. 58
      src/str.cpp
  3. 15
      src/str.hpp

4
src/option_parser.cpp

@ -133,7 +133,9 @@ set_fsname(struct fuse_args &args,
{ {
std::string fsname; std::string fsname;
fsname = "-ofsname=" + str::join(config.srcmounts,':');
fsname =
"-ofsname=" +
str::remove_common_prefix_and_join(config.srcmounts,':');
fuse_opt_insert_arg(&args,1,fsname.c_str()); fuse_opt_insert_arg(&args,1,fsname.c_str());
} }

58
src/str.cpp

@ -46,15 +46,69 @@ namespace str
string string
join(const vector<string> &vec, join(const vector<string> &vec,
const size_t substridx,
const char sep) const char sep)
{ {
if(vec.empty()) if(vec.empty())
return string(); return string();
string rv = vec[0];
string rv = vec[0].substr(substridx);
for(size_t i = 1; i < vec.size(); i++) for(size_t i = 1; i < vec.size(); i++)
rv += sep + vec[i];
rv += sep + vec[i].substr(substridx);
return rv; return rv;
} }
string
join(const vector<string> &vec,
const char sep)
{
return str::join(vec,0,sep);
}
size_t
longest_common_prefix_index(const vector<string> &vec)
{
if(vec.empty())
return string::npos;
for(size_t n = 0; n < vec[0].size(); n++)
{
char chr = vec[0][n];
for(size_t i = 1; i < vec.size(); i++)
{
if(n >= vec[i].size())
return n;
if(vec[i][n] != chr)
return n;
}
}
return string::npos;
}
string
longest_common_prefix(const vector<string> &vec)
{
size_t idx;
idx = longest_common_prefix_index(vec);
if(idx != string::npos)
return vec[0].substr(0,idx);
return string();
}
string
remove_common_prefix_and_join(const vector<string> &vec,
const char sep)
{
size_t idx;
idx = str::longest_common_prefix_index(vec);
if(idx == string::npos)
idx = 0;
return str::join(vec,idx,sep);
}
} }

15
src/str.hpp

@ -34,5 +34,20 @@ namespace str
std::string std::string
join(const std::vector<std::string> &vec, join(const std::vector<std::string> &vec,
const size_t substridx,
const char sep);
std::string
join(const std::vector<std::string> &vec,
const char sep);
size_t
longest_common_prefix_index(const std::vector<std::string> &vec);
std::string
longest_common_prefix(const std::vector<std::string> &vec);
std::string
remove_common_prefix_and_join(const std::vector<std::string> &vec,
const char sep); const char sep);
} }
Loading…
Cancel
Save