mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleanup wordRe interfaces etc.
- ensure that the string-related classes have consistently similar
matching methods. Use operator()(const std::string) as an entry
point for the match() method, which makes it easier to use for
filters and predicates. In some cases this will also permit using
a HashSet as a match predicate.
regExp
====
- the set method now returns a bool to signal that the requested
pattern was compiled.
wordRe
====
- have separate constructors with the compilation option (was previously
a default parameter). This leaves the single parameter constructor
explicit, but the two parameter version is now non-explicit, which
makes it easier to use when building lists.
- renamed compile-option from REGEX (to REGEXP) for consistency with
with the <regex.h>, <regex> header names etc.
wordRes
====
- renamed from wordReListMatcher -> wordRes. For reduced typing and
since it behaves as an entity only slightly related to its underlying
list nature.
- Provide old name as typedef and include for code transition.
- pass through some list methods into wordRes
hashedWordList
====
- hashedWordList[const word& name] now returns a -1 if the name is is
not found in the list of indices. That has been a pending change
ever since hashedWordList was generalized out of speciesTable
(Oct-2010).
- add operator()(const word& name) for easy use as a predicate
STYLE: adjust parameter names in stringListOps
- reflect if the parameter is being used as a primary matcher, or the
matcher will be derived from the parameter.
For example,
(const char* re), which first creates a regExp
versus (const regExp& matcher) which is used directly.
This commit is contained in:
@ -94,7 +94,9 @@ public:
|
||||
hash()
|
||||
{}
|
||||
|
||||
inline unsigned operator()(const string&, unsigned seed = 0) const;
|
||||
//- Hash for string.
|
||||
// Uses Foam::string instead of std::string for automatic conversions.
|
||||
inline unsigned operator()(const string& str, unsigned seed = 0) const;
|
||||
};
|
||||
|
||||
|
||||
@ -109,7 +111,7 @@ public:
|
||||
//- Construct as copy of character array
|
||||
inline string(const char* str);
|
||||
|
||||
//- Construct as copy of specified number of characters
|
||||
//- Construct as copy with a maximum number of characters
|
||||
inline string(const char* str, const size_type len);
|
||||
|
||||
//- Construct from a single character
|
||||
@ -222,14 +224,18 @@ public:
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Return the sub-string from the i-th character for \a n characters
|
||||
//- Match text
|
||||
// \return True when strings match literally.
|
||||
inline bool operator()(const std::string& text) const;
|
||||
|
||||
//- Return sub-string from the i-th character for \a n characters
|
||||
inline string operator()
|
||||
(
|
||||
const size_type i,
|
||||
const size_type n
|
||||
) const;
|
||||
|
||||
//- Return the sub-string from the first character for \a n characters
|
||||
//- Return sub-string from the first character for \a n characters
|
||||
inline string operator()
|
||||
(
|
||||
const size_type n
|
||||
|
||||
@ -178,15 +178,21 @@ inline String Foam::string::validate(const std::string& str)
|
||||
return ss;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::string::match(const std::string& text) const
|
||||
{
|
||||
// check as string
|
||||
return (text == *this);
|
||||
return !compare(text); // Always compare as literal string
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::string::operator()(const std::string& text) const
|
||||
{
|
||||
return !compare(text); // Always compare as literal string
|
||||
}
|
||||
|
||||
|
||||
inline Foam::string Foam::string::operator()
|
||||
(
|
||||
const size_type i,
|
||||
@ -205,11 +211,11 @@ inline Foam::string Foam::string::operator()(const size_type n) const
|
||||
|
||||
inline unsigned Foam::string::hash::operator()
|
||||
(
|
||||
const string& key,
|
||||
const string& str,
|
||||
unsigned seed
|
||||
) const
|
||||
{
|
||||
return Hasher(key.data(), key.size(), seed);
|
||||
return Hasher(str.data(), str.size(), seed);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user