wxCStrData operator+(size_t n) const
{ return wxCStrData(m_str, m_offset + n, m_owned); }
- // and these for "str.c_str() + n - 2":
- wxCStrData operator-(int n) const
+ // and these for "str.c_str() + (p2 - p1)" (it also works for any integer
+ // expression but it must be ptrdiff_t and not e.g. int to work in this
+ // example):
+ wxCStrData operator-(ptrdiff_t n) const
{
- wxASSERT_MSG( n <= (int)m_offset,
- _T("attempt to construct address before the beginning of the string") );
- return wxCStrData(m_str, m_offset - n, m_owned);
- }
- wxCStrData operator-(long n) const
- {
- wxASSERT_MSG( n <= (int)m_offset,
- _T("attempt to construct address before the beginning of the string") );
- return wxCStrData(m_str, m_offset - n, m_owned);
- }
- wxCStrData operator-(size_t n) const
- {
- wxASSERT_MSG( n <= m_offset,
+ wxASSERT_MSG( n <= (ptrdiff_t)m_offset,
_T("attempt to construct address before the beginning of the string") );
return wxCStrData(m_str, m_offset - n, m_owned);
}
return tmp; \
} \
\
- iterator_name& operator+=(int n) \
+ iterator_name& operator+=(ptrdiff_t n) \
{ \
m_cur = wxStringOperations::AddToIter(m_cur, n); \
return *this; \
} \
- iterator_name& operator+=(size_t n) \
- { \
- m_cur = wxStringOperations::AddToIter(m_cur, (int)n); \
- return *this; \
- } \
- iterator_name& operator-=(int n) \
+ iterator_name& operator-=(ptrdiff_t n) \
{ \
m_cur = wxStringOperations::AddToIter(m_cur, -n); \
return *this; \
- } \
- iterator_name& operator-=(size_t n) \
- { \
- m_cur = wxStringOperations::AddToIter(m_cur, -(int)n); \
- return *this; \
} \
\
difference_type operator-(const iterator_name& i) const \
reference operator*()
{ return wxUniCharRef::CreateForString(m_node, m_cur); }
- iterator operator+(int n) const
+ iterator operator+(ptrdiff_t n) const
{ return iterator(str(), wxStringOperations::AddToIter(m_cur, n)); }
- iterator operator+(size_t n) const
- { return iterator(str(), wxStringOperations::AddToIter(m_cur, (int)n)); }
- iterator operator-(int n) const
+ iterator operator-(ptrdiff_t n) const
{ return iterator(str(), wxStringOperations::AddToIter(m_cur, -n)); }
- iterator operator-(size_t n) const
- { return iterator(str(), wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
iterator(wxString *str, underlying_iterator ptr)
reference operator*() const
{ return wxStringOperations::DecodeChar(m_cur); }
- const_iterator operator+(int n) const
+ const_iterator operator+(ptrdiff_t n) const
{ return const_iterator(str(), wxStringOperations::AddToIter(m_cur, n)); }
- const_iterator operator+(size_t n) const
- { return const_iterator(str(), wxStringOperations::AddToIter(m_cur, (int)n)); }
- const_iterator operator-(int n) const
+ const_iterator operator-(ptrdiff_t n) const
{ return const_iterator(str(), wxStringOperations::AddToIter(m_cur, -n)); }
- const_iterator operator-(size_t n) const
- { return const_iterator(str(), wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
// for internal wxString use only:
reference operator*()
{ return wxUniCharRef::CreateForString(m_cur); }
- iterator operator+(int n) const
+ iterator operator+(ptrdiff_t n) const
{ return iterator(wxStringOperations::AddToIter(m_cur, n)); }
- iterator operator+(size_t n) const
- { return iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
- iterator operator-(int n) const
+ iterator operator-(ptrdiff_t n) const
{ return iterator(wxStringOperations::AddToIter(m_cur, -n)); }
- iterator operator-(size_t n) const
- { return iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
// for internal wxString use only:
reference operator*() const
{ return wxStringOperations::DecodeChar(m_cur); }
- const_iterator operator+(int n) const
+ const_iterator operator+(ptrdiff_t n) const
{ return const_iterator(wxStringOperations::AddToIter(m_cur, n)); }
- const_iterator operator+(size_t n) const
- { return const_iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
- const_iterator operator-(int n) const
+ const_iterator operator-(ptrdiff_t n) const
{ return const_iterator(wxStringOperations::AddToIter(m_cur, -n)); }
- const_iterator operator-(size_t n) const
- { return const_iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
// for internal wxString use only:
{ reverse_iterator_impl tmp = *this; ++m_cur; return tmp; }
// NB: explicit <T> in the functions below is to keep BCC 5.5 happy
- reverse_iterator_impl operator+(int n) const
+ reverse_iterator_impl operator+(ptrdiff_t n) const
{ return reverse_iterator_impl<T>(m_cur - n); }
- reverse_iterator_impl operator+(size_t n) const
- { return reverse_iterator_impl<T>(m_cur - n); }
- reverse_iterator_impl operator-(int n) const
- { return reverse_iterator_impl<T>(m_cur + n); }
- reverse_iterator_impl operator-(size_t n) const
+ reverse_iterator_impl operator-(ptrdiff_t n) const
{ return reverse_iterator_impl<T>(m_cur + n); }
- reverse_iterator_impl operator+=(int n)
- { m_cur -= n; return *this; }
- reverse_iterator_impl operator+=(size_t n)
+ reverse_iterator_impl operator+=(ptrdiff_t n)
{ m_cur -= n; return *this; }
- reverse_iterator_impl operator-=(int n)
- { m_cur += n; return *this; }
- reverse_iterator_impl operator-=(size_t n)
+ reverse_iterator_impl operator-=(ptrdiff_t n)
{ m_cur += n; return *this; }
unsigned operator-(const reverse_iterator_impl& i) const
// string iterator operators that satisfy STL Random Access Iterator
// requirements:
-inline wxString::iterator operator+(int n, wxString::iterator i)
- { return i + n; }
-inline wxString::iterator operator+(size_t n, wxString::iterator i)
- { return i + n; }
-inline wxString::const_iterator operator+(int n, wxString::const_iterator i)
- { return i + n; }
-inline wxString::const_iterator operator+(size_t n, wxString::const_iterator i)
- { return i + n; }
-inline wxString::reverse_iterator operator+(int n, wxString::reverse_iterator i)
+inline wxString::iterator operator+(ptrdiff_t n, wxString::iterator i)
{ return i + n; }
-inline wxString::reverse_iterator operator+(size_t n, wxString::reverse_iterator i)
+inline wxString::const_iterator operator+(ptrdiff_t n, wxString::const_iterator i)
{ return i + n; }
-inline wxString::const_reverse_iterator operator+(int n, wxString::const_reverse_iterator i)
+inline wxString::reverse_iterator operator+(ptrdiff_t n, wxString::reverse_iterator i)
{ return i + n; }
-inline wxString::const_reverse_iterator operator+(size_t n, wxString::const_reverse_iterator i)
+inline wxString::const_reverse_iterator operator+(ptrdiff_t n, wxString::const_reverse_iterator i)
{ return i + n; }
// notice that even though for many compilers the friend declarations above are
static void DecIter(wxStringImpl::const_iterator& i) { --i; }
// moves the iterator by n Unicode characters
- static wxStringImpl::iterator AddToIter(const wxStringImpl::iterator& i, int n)
+ static wxStringImpl::iterator AddToIter(const wxStringImpl::iterator& i, ptrdiff_t n)
{ return i + n; }
- static wxStringImpl::const_iterator AddToIter(const wxStringImpl::const_iterator& i, int n)
+ static wxStringImpl::const_iterator AddToIter(const wxStringImpl::const_iterator& i, ptrdiff_t n)
{ return i + n; }
// returns distance of the two iterators in Unicode characters
- static int DiffIters(const wxStringImpl::iterator& i1,
- const wxStringImpl::iterator& i2)
+ static ptrdiff_t DiffIters(const wxStringImpl::iterator& i1,
+ const wxStringImpl::iterator& i2)
{ return i1 - i2; }
- static int DiffIters(const wxStringImpl::const_iterator& i1,
- const wxStringImpl::const_iterator& i2)
+ static ptrdiff_t DiffIters(const wxStringImpl::const_iterator& i1,
+ const wxStringImpl::const_iterator& i2)
{ return i1 - i2; }
// encodes the character to a form used to represent it in internal
}
template<typename Iterator>
- static Iterator AddToIter(const Iterator& i, int n)
+ static Iterator AddToIter(const Iterator& i, ptrdiff_t n)
{
Iterator out(i);
if ( n > 0 )
{
- for ( int j = 0; j < n; ++j )
+ for ( ptrdiff_t j = 0; j < n; ++j )
IncIter(out);
}
else if ( n < 0 )
{
- for ( int j = 0; j > n; --j )
+ for ( ptrdiff_t j = 0; j > n; --j )
DecIter(out);
}
}
template<typename Iterator>
- static int DiffIters(Iterator i1, Iterator i2)
+ static ptrdiff_t DiffIters(Iterator i1, Iterator i2)
{
- int dist = 0;
+ ptrdiff_t dist = 0;
if ( i1 < i2 )
{