Tab completion functional.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@357 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-03-17 01:07:54 +00:00
parent 8090d4db26
commit cefa2b584d
13 changed files with 275 additions and 17 deletions
+42
View File
@@ -75,6 +75,48 @@ advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __las
return std::make_pair(__middle1, __middle2);
}
struct
string_starts_with : public std::binary_function<std::string, std::string, bool> {
bool operator () (const std::string& complete, const std::string& base) const {
return !complete.compare(0, base.size(), base);
}
};
// Count the number of elements from the start of the containers to
// the first inequal element.
template <typename _InputIter>
typename std::iterator_traits<_InputIter>::difference_type
count_base(_InputIter __first1, _InputIter __last1,
_InputIter __first2, _InputIter __last2) {
typename std::iterator_traits<_InputIter>::difference_type __n = 0;
for ( ;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2, ++__n)
if (*__first1 != *__first2)
return __n;
return __n;
}
template <typename _InputIter>
typename std::iterator_traits<_InputIter>::value_type
make_base(_InputIter __first, _InputIter __last) {
if (__first == __last)
return "";
typename std::iterator_traits<_InputIter>::value_type __base = *__first++;
for ( ;__first != __last; ++__first) {
typename std::iterator_traits<_InputIter>::difference_type __pos = count_base(__base.begin(), __base.end(),
__first->begin(), __first->end());
if (__pos < __base.size())
__base.resize(__pos);
}
return __base;
}
}
#endif