// Components for manipulating sequences of characters -*- C++ -*-
-// Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
int
compare(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2 = npos) const;
-
- private:
- static const _CharT*
- _S_find(const _CharT* __beg, const _CharT* __end, _CharT __c);
};
return __n;
}
- // String operations
- template<typename _CharT, typename _Traits, typename _Alloc>
- const _CharT*
- basic_string<_CharT, _Traits, _Alloc>::
- _S_find(const _CharT* __beg, const _CharT* __end, _CharT __c)
- {
- return find_if(__beg, __end, _Char_traits_match<_CharT, _Traits>(__c));
- }
-
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find(const _CharT* __s, size_type __pos, size_type __n) const
{
+ size_type __size = this->size();
size_t __xpos = __pos;
const _CharT* __data = _M_data();
- for (; __xpos + __n <= this->size(); ++__xpos)
+ for (; __xpos + __n <= __size; ++__xpos)
if (traits_type::compare(__data + __xpos, __s, __n) == 0)
return __xpos;
return npos;
if (__pos < __size)
{
const _CharT* __data = _M_data();
- const _CharT* __end = __data + __size;
- const _CharT* __p = _S_find(__data + __pos, __end, __c);
- if (__p != __end)
+ size_type __n = __size - __pos;
+ const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
+ if (__p)
__ret = __p - __data;
}
return __ret;
basic_string<_CharT, _Traits, _Alloc>::
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
{
- const _CharT* __end = __s + __n;
for (; __n && __pos < this->size(); ++__pos)
{
- const _CharT* __p = _S_find(__s, __end, _M_data()[__pos]);
- if (__p != __end)
+ const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]);
+ if (__p)
return __pos;
}
return npos;
__size = __pos;
do
{
- const _CharT* __p = _S_find(__s, __s + __n, _M_data()[__size]);
- if (__p != __s + __n)
+ if (traits_type::find(__s, __n, _M_data()[__size]))
return __size;
}
while (__size-- != 0);
{
size_t __xpos = __pos;
for (; __n && __xpos < this->size(); ++__xpos)
- if (_S_find(__s, __s + __n, _M_data()[__xpos]) == __s + __n)
+ if (!traits_type::find(__s, __n, _M_data()[__xpos]))
return __xpos;
return npos;
}
find_first_not_of(_CharT __c, size_type __pos) const
{
size_t __xpos = __pos;
- for (; __xpos < size(); ++__xpos)
+ for (; __xpos < this->size(); ++__xpos)
if (!traits_type::eq(_M_data()[__xpos], __c))
return __xpos;
return npos;
__size = __pos;
do
{
- if (_S_find(__s, __s + __n, _M_data()[__size]) == __s + __n)
+ if (!traits_type::find(__s, __n, _M_data()[__size]))
return __size;
}
while (__size--);
// Character Traits for use by standard string and iostream -*- C++ -*-
-// Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
+// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{ return eq_int_type(__c, eof()) ? int_type(0) : __c; }
};
+
// 21.1.4 char_traits specializations
template<>
struct char_traits<char>
_Char_traits_match(_CharT const& __c) : _M_c(__c) { }
bool
- operator()(_CharT const& __a) { return _Traits::eq(_M_c,__a); }
+ operator()(_CharT const& __a) { return _Traits::eq(_M_c, __a); }
};
} // namespace std