tahonermann / text_view

A C++ concepts and range based character encoding and code point enumeration library
MIT License
122 stars 14 forks source link

Add a policy class template parameter to basic_text_view and itext_iterator to enable custom error handling #14

Closed tahonermann closed 7 years ago

tahonermann commented 8 years ago

At present, underflow and invalid code unit sequences result in exceptions being thrown from itext_iterator advance operations. These operators can't return errors in any other way and still be usable as generic iterators. Yet, use of exceptions is not acceptable to many members of the C++ community.

Custom error handling could be provided by adding a policy class template parameter to basic_text_view and itext_iterator. The policy class would have member functions that would be called in underflow or invalid code unit sequences. Those functions could then throw custom exceptions, record errors elsewhere, signal that incomplete code unit sequences should be saved as state in the iterator (which would then compare equal to the end iterator), provide substitution characters for invalid code unit sequences, etc...

tahonermann commented 7 years ago

Closing this issue as resolved by the introduction of error policies in commit 4950cdfda13cbfc9a20fcfbf4c85a7a9fcf1f8c6. The current error policy classes are simpler than what was suggested in the writeup for this issue (no member functions), but I think suffices.