Skip to content
Snippets Groups Projects
Commit 5382ce77 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: allow alternative delimiter for fileName::concat. Default: '/'

parent e3b05494
Branches
Tags
No related merge requests found
......@@ -124,7 +124,8 @@ Foam::fileName Foam::fileName::validate
Foam::fileName Foam::fileName::concat
(
const std::string& s1,
const std::string& s2
const std::string& s2,
const char delim
)
{
const auto n1 = s1.length();
......@@ -135,10 +136,10 @@ Foam::fileName Foam::fileName::concat
out += s1;
if (n1 && n2 && s1.back() != '/' && s2.front() != '/')
if (n1 && n2 && s1.back() != delim && s2.front() != delim)
{
// Add separator
out += '/';
// Add delimiter
out += delim;
}
out += s2;
......@@ -473,9 +474,9 @@ bool Foam::fileName::hasExt(const wordRe& ending) const
}
Foam::wordList Foam::fileName::components(const char delimiter) const
Foam::wordList Foam::fileName::components(const char delim) const
{
const auto parsed = stringOps::split<string>(*this, delimiter);
const auto parsed = stringOps::split<string>(*this, delim);
wordList words(parsed.size());
......@@ -495,10 +496,10 @@ Foam::wordList Foam::fileName::components(const char delimiter) const
Foam::word Foam::fileName::component
(
const size_type cmpt,
const char delimiter
const char delim
) const
{
const auto parsed = stringOps::split<string>(*this, delimiter);
const auto parsed = stringOps::split<string>(*this, delim);
if (cmpt < parsed.size())
{
......
......@@ -149,11 +149,16 @@ public:
//- removing duplicate or trailing slashes, etc.
static fileName validate(const std::string& s, const bool doClean=true);
//- Join two strings with '/' as a path separator.
// No '/' separator is added if either argument is an empty string or
//- Join two strings with a path separator ('/' by default).
// No separator is added if either argument is an empty string or
// if the arguments already had the path separator at the junction.
// Invalid characters are \em not stripped (ie, retained).
static fileName concat(const std::string& s1, const std::string& s2);
static fileName concat
(
const std::string& s1,
const std::string& s2,
const char delim = '/'
);
//- This is a specialized (possibly slower) version of compare()
//- that ignores duplicate or trailing slashes.
......@@ -343,14 +348,10 @@ public:
// "/abc/def" ("abc", "def")
// "/abc/def/" ("abc", "def")
// \endverbatim
wordList components(const char delimiter = '/') const;
wordList components(const char delim = '/') const;
//- Return a single component of the path
word component
(
const size_type cmpt,
const char delimiter = '/'
) const;
word component(const size_type cmpt, const char delim = '/') const;
// Member Operators
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment