mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
refactors stringops.hpp (#3192)
With this PR we refactor `StringUtils::replaceAll` to accept `string_view` as suggested in a code comment. In addition, while we are touching this rebuild happy file, we slim it down a bit by moving a few sparingly used functions elsewhere.
This commit is contained in:
parent
5debd6e25a
commit
1960e976e2
11 changed files with 119 additions and 136 deletions
|
@ -4,6 +4,8 @@
|
|||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "stringops.hpp"
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
template <typename Iterator, typename BinaryPredicate, typename Function>
|
||||
|
@ -31,6 +33,30 @@ namespace Misc
|
|||
}
|
||||
return begin;
|
||||
}
|
||||
|
||||
/// Performs a binary search on a sorted container for a string that 'key' starts with
|
||||
template<typename Iterator, typename T>
|
||||
static Iterator partialBinarySearch(Iterator begin, Iterator end, const T& key)
|
||||
{
|
||||
const Iterator notFound = end;
|
||||
|
||||
while(begin < end)
|
||||
{
|
||||
const Iterator middle = begin + (std::distance(begin, end) / 2);
|
||||
|
||||
int comp = Misc::StringUtils::ciCompareLen((*middle), key, (*middle).size());
|
||||
|
||||
if(comp == 0)
|
||||
return middle;
|
||||
else if(comp > 0)
|
||||
end = middle;
|
||||
else
|
||||
begin = middle + 1;
|
||||
}
|
||||
|
||||
return notFound;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue