closeEnough
- Implemented closeEnough, which does a truncated, caseless compare between two strings. For example, "FoO" is cloneEnough to "food." to be a match. Used to allow mixed case and abbreviated arguments.
This commit is contained in:
12
src/text.cpp
12
src/text.cpp
@@ -617,6 +617,18 @@ bool compare (
|
||||
return left == right;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool closeEnough (const std::string& reference, const std::string& attempt)
|
||||
{
|
||||
if (compare (reference, attempt, false))
|
||||
return true;
|
||||
|
||||
if (attempt.length () < reference.length ())
|
||||
return compare (reference.substr (0, attempt.length ()), attempt, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string::size_type find (
|
||||
const std::string& text,
|
||||
|
||||
Reference in New Issue
Block a user