mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: tune efficiency of stringOps::trim
- move left/right positions prior to substr
This commit is contained in:
committed by
Andrew Heather
parent
60155bd90d
commit
71de630722
@ -70,7 +70,7 @@ int main(int argc, char *argv[])
|
||||
" $(DONOTSUBST) some other <${USER}> with '${__UNKNOWN:-some default}'"
|
||||
" value "
|
||||
" or with '${HOME:+Home was set}' via :+ alternative"
|
||||
" or with '${__UNKNOWN:+unknown}' empty"
|
||||
" or with '${__UNKNOWN:+unknown}' empty "
|
||||
);
|
||||
|
||||
setEnv("FOAM_CASE", cwd(), true);
|
||||
|
||||
@ -742,12 +742,12 @@ std::string::size_type Foam::stringOps::count(const char* str, const char c)
|
||||
|
||||
Foam::string Foam::stringOps::expand
|
||||
(
|
||||
const std::string& original,
|
||||
const std::string& str,
|
||||
const HashTable<string, word, string::hash>& mapping,
|
||||
const char sigil
|
||||
)
|
||||
{
|
||||
string s(original);
|
||||
string s(str);
|
||||
inplaceExpand(s, mapping);
|
||||
return s;
|
||||
}
|
||||
@ -877,12 +877,12 @@ void Foam::stringOps::inplaceExpand
|
||||
|
||||
Foam::string Foam::stringOps::expand
|
||||
(
|
||||
const std::string& original,
|
||||
const std::string& str,
|
||||
const dictionary& dict,
|
||||
const char sigil
|
||||
)
|
||||
{
|
||||
string s(original);
|
||||
string s(str);
|
||||
inplaceExpand(s, dict, sigil);
|
||||
return s;
|
||||
}
|
||||
@ -917,11 +917,11 @@ void Foam::stringOps::inplaceExpand
|
||||
|
||||
Foam::string Foam::stringOps::expand
|
||||
(
|
||||
const std::string& original,
|
||||
const std::string& str,
|
||||
const bool allowEmpty
|
||||
)
|
||||
{
|
||||
string s(original);
|
||||
string s(str);
|
||||
inplaceExpand(s, allowEmpty);
|
||||
return s;
|
||||
}
|
||||
@ -1036,11 +1036,24 @@ void Foam::stringOps::inplaceTrimRight(std::string& s)
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::stringOps::trim(const std::string& original)
|
||||
Foam::string Foam::stringOps::trim(const std::string& str)
|
||||
{
|
||||
string s(original);
|
||||
inplaceTrim(s);
|
||||
return s;
|
||||
std::string::size_type beg = 0;
|
||||
std::string::size_type end = str.size();
|
||||
|
||||
// Right
|
||||
while (beg < end && std::isspace(str[end-1]))
|
||||
{
|
||||
--end;
|
||||
}
|
||||
|
||||
// Left
|
||||
while (beg < end && std::isspace(str[beg]))
|
||||
{
|
||||
++beg;
|
||||
}
|
||||
|
||||
return str.substr(beg, end-beg);
|
||||
}
|
||||
|
||||
|
||||
@ -1051,9 +1064,9 @@ void Foam::stringOps::inplaceTrim(std::string& s)
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::stringOps::removeComments(const std::string& original)
|
||||
Foam::string Foam::stringOps::removeComments(const std::string& str)
|
||||
{
|
||||
string s(original);
|
||||
string s(str);
|
||||
inplaceRemoveComments(s);
|
||||
return s;
|
||||
}
|
||||
@ -1135,9 +1148,9 @@ void Foam::stringOps::inplaceRemoveComments(std::string& s)
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::stringOps::lower(const std::string& original)
|
||||
Foam::string Foam::stringOps::lower(const std::string& str)
|
||||
{
|
||||
string s(original);
|
||||
string s(str);
|
||||
inplaceLower(s);
|
||||
return s;
|
||||
}
|
||||
@ -1155,9 +1168,9 @@ void Foam::stringOps::inplaceLower(std::string& s)
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::stringOps::upper(const std::string& original)
|
||||
Foam::string Foam::stringOps::upper(const std::string& str)
|
||||
{
|
||||
string s(original);
|
||||
string s(str);
|
||||
inplaceUpper(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ namespace stringOps
|
||||
// \sa stringOps::inplaceExpand() for details
|
||||
string expand
|
||||
(
|
||||
const std::string& original,
|
||||
const std::string& str,
|
||||
const HashTable<string, word, string::hash>& mapping,
|
||||
const char sigil = '$'
|
||||
);
|
||||
@ -206,7 +206,7 @@ namespace stringOps
|
||||
// \sa stringOps::inplaceExpand(std::string&, const dictionary&, char)
|
||||
string expand
|
||||
(
|
||||
const std::string& original,
|
||||
const std::string& str,
|
||||
const dictionary& dict,
|
||||
const char sigil = '$'
|
||||
);
|
||||
@ -232,7 +232,7 @@ namespace stringOps
|
||||
// stringOps::inplaceExpand(std::string&, bool);
|
||||
string expand
|
||||
(
|
||||
const std::string& original,
|
||||
const std::string& str,
|
||||
const bool allowEmpty = false
|
||||
);
|
||||
|
||||
@ -271,27 +271,27 @@ namespace stringOps
|
||||
void inplaceTrimRight(std::string& s);
|
||||
|
||||
//- Return string trimmed of leading and trailing whitespace
|
||||
string trim(const std::string& original);
|
||||
string trim(const std::string& str);
|
||||
|
||||
//- Trim leading and trailing whitespace inplace
|
||||
void inplaceTrim(std::string& s);
|
||||
|
||||
|
||||
//- Return string with C/C++ comments removed
|
||||
string removeComments(const std::string& original);
|
||||
string removeComments(const std::string& str);
|
||||
|
||||
//- Remove C/C++ comments inplace
|
||||
void inplaceRemoveComments(std::string& s);
|
||||
|
||||
|
||||
//- Return string transformed with std::tolower on each character
|
||||
string lower(const std::string& original);
|
||||
string lower(const std::string& str);
|
||||
|
||||
//- Inplace transform string with std::tolower on each character
|
||||
void inplaceLower(std::string& s);
|
||||
|
||||
//- Return string transformed with std::toupper on each character
|
||||
string upper(const std::string& original);
|
||||
string upper(const std::string& str);
|
||||
|
||||
//- Inplace transform string with std::toupper on each character
|
||||
void inplaceUpper(std::string& s);
|
||||
|
||||
Reference in New Issue
Block a user