utf8: replace InvalidBytePolicy::Throw with InvalidBytePolicy::Assert

This commit is contained in:
Maxime Coste 2012-10-17 17:01:51 +02:00
parent c1387dc592
commit df400f90ab
2 changed files with 5 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#include <cstddef> #include <cstddef>
#include "unicode.hh" #include "unicode.hh"
#include "assert.hh"
namespace Kakoune namespace Kakoune
{ {
@ -79,14 +80,12 @@ bool is_character_start(Iterator it)
return (*it & 0xC0) != 0x80; return (*it & 0xC0) != 0x80;
} }
struct invalid_utf8_sequence{};
namespace InvalidBytePolicy namespace InvalidBytePolicy
{ {
struct Throw struct Assert
{ {
Codepoint operator()(char byte) const { throw invalid_utf8_sequence{}; } Codepoint operator()(char byte) const { assert(false); return byte; }
}; };
struct Pass struct Pass
@ -98,7 +97,7 @@ struct Pass
// returns the codepoint of the character whose first byte // returns the codepoint of the character whose first byte
// is pointed by it // is pointed by it
template<typename InvalidPolicy = InvalidBytePolicy::Throw, template<typename InvalidPolicy = InvalidBytePolicy::Assert,
typename Iterator> typename Iterator>
Codepoint codepoint(Iterator it) Codepoint codepoint(Iterator it)
{ {

View File

@ -12,7 +12,7 @@ namespace utf8
// adapter for an iterator on bytes which permits to iterate // adapter for an iterator on bytes which permits to iterate
// on unicode codepoints instead. // on unicode codepoints instead.
template<typename Iterator, template<typename Iterator,
typename InvalidPolicy = InvalidBytePolicy::Throw> typename InvalidPolicy = InvalidBytePolicy::Assert>
class utf8_iterator class utf8_iterator
{ {
public: public: