mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add move/swap semantics to string types and regExp
- move append() single element to List and DynamicList ENH: add stringOps::count to avoid unnecessary string conversions
This commit is contained in:
@ -132,6 +132,47 @@ static inline int findParameterAlternative
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
std::string::size_type Foam::stringOps::count
|
||||
(
|
||||
const std::string& str,
|
||||
const char c
|
||||
)
|
||||
{
|
||||
std::string::size_type n = 0;
|
||||
|
||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||
{
|
||||
if (*iter == c)
|
||||
{
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
std::string::size_type Foam::stringOps::count(const char* str, const char c)
|
||||
{
|
||||
if (!str)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string::size_type n = 0;
|
||||
|
||||
for (const char *iter = str; *iter; ++iter)
|
||||
{
|
||||
if (*iter == c)
|
||||
{
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::stringOps::expand
|
||||
(
|
||||
const string& original,
|
||||
|
||||
Reference in New Issue
Block a user