Added the unchecked iterator, added base() to the checked one, updated tests
git-svn-id: http://svn.code.sf.net/p/utfcpp/code@69 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
parent
a42b82da3a
commit
bfb37e9c26
3 changed files with 61 additions and 1 deletions
|
@ -250,11 +250,12 @@ namespace utf8
|
|||
|
||||
// The iterator class
|
||||
template <typename octet_iterator>
|
||||
class iterator {
|
||||
class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
|
||||
octet_iterator it;
|
||||
octet_iterator range_start;
|
||||
octet_iterator range_end;
|
||||
public:
|
||||
iterator () {};
|
||||
explicit iterator (const octet_iterator& octet_it,
|
||||
const octet_iterator& range_start,
|
||||
const octet_iterator& range_end) :
|
||||
|
@ -264,6 +265,7 @@ namespace utf8
|
|||
throw std::out_of_range("Invalid utf-8 iterator position");
|
||||
}
|
||||
// the default "big three" are OK
|
||||
octet_iterator base () const { return it; }
|
||||
uint32_t operator * () const
|
||||
{
|
||||
octet_iterator temp = it;
|
||||
|
|
|
@ -167,6 +167,48 @@ namespace utf8
|
|||
return result;
|
||||
}
|
||||
|
||||
// The iterator class
|
||||
template <typename octet_iterator>
|
||||
class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
|
||||
octet_iterator it;
|
||||
public:
|
||||
iterator () {};
|
||||
explicit iterator (const octet_iterator& octet_it): it(octet_it) {}
|
||||
// the default "big three" are OK
|
||||
octet_iterator base () const { return it; }
|
||||
uint32_t operator * () const
|
||||
{
|
||||
octet_iterator temp = it;
|
||||
return next(temp);
|
||||
}
|
||||
bool operator == (const iterator& rhs) const
|
||||
{
|
||||
return (it == rhs.it);
|
||||
}
|
||||
iterator& operator ++ ()
|
||||
{
|
||||
next(it);
|
||||
return *this;
|
||||
}
|
||||
iterator operator ++ (int)
|
||||
{
|
||||
iterator temp = *this;
|
||||
next(it);
|
||||
return temp;
|
||||
}
|
||||
iterator& operator -- ()
|
||||
{
|
||||
prior(it);
|
||||
return *this;
|
||||
}
|
||||
iterator operator -- (int)
|
||||
{
|
||||
iterator temp = *this;
|
||||
prior(it);
|
||||
return temp;
|
||||
}
|
||||
}; // class iterator
|
||||
|
||||
} // namespace utf8::unchecked
|
||||
} // namespace utf8
|
||||
|
||||
|
|
|
@ -257,6 +257,22 @@ int main()
|
|||
// try it with the return value;
|
||||
utf16_end = utf8to16 (utf8_with_surrogates, utf8_with_surrogates + 9, &utf16result[0]);
|
||||
assert (utf16_end == &utf16result[0] + 4);
|
||||
|
||||
// iterator
|
||||
utf8::unchecked::iterator<char*> un_it(threechars);
|
||||
utf8::unchecked::iterator<char*> un_it2 = un_it;
|
||||
assert (un_it2 == un_it);
|
||||
assert (*un_it == 0x10346);
|
||||
assert (*(++un_it) == 0x65e5);
|
||||
assert ((*un_it++) == 0x65e5);
|
||||
assert (*un_it == 0x0448);
|
||||
utf8::unchecked::iterator<char*> un_endit (threechars + 9);
|
||||
assert (++un_it == un_endit);
|
||||
assert (*(--un_it) == 0x0448);
|
||||
assert ((*un_it--) == 0x0448);
|
||||
assert (*un_it == 0x65e5);
|
||||
assert (--un_it == utf8::unchecked::iterator<char*>(threechars));
|
||||
assert (*un_it == 0x10346);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue