Implemented utf::next in terms of internal::validate_next

git-svn-id: http://svn.code.sf.net/p/utfcpp/code@15 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
ntrifunovic 2006-07-20 15:47:16 +00:00
parent a0800ac8f1
commit f7e5f04087

View file

@ -129,7 +129,7 @@ namespace internal
else else
return INVALID_LEAD; return INVALID_LEAD;
// Do we have enough memory? // Do we have enough memory?
if (end - it < sequence_length) if (size_t(end - it) < sequence_length)
return NOT_ENOUGH_ROOM; return NOT_ENOUGH_ROOM;
// Check trail octets and calculate the code point // Check trail octets and calculate the code point
@ -262,73 +262,20 @@ namespace internal
template <typename octet_iterator> template <typename octet_iterator>
uint32_t next(octet_iterator& it, octet_iterator end) uint32_t next(octet_iterator& it, octet_iterator end)
{ {
uint32_t cp = internal::mask8(*it); uint32_t cp = 0;
if (cp < 0x80) internal::utf_error err_code = internal::validate_next(it, end, &cp);
; switch (err_code) {
else if ((internal::mask8(*it) >> 5) == 0x6) { case internal::OK :
if (++it != end) { break;
if (internal::is_trail(*it)) { case internal::NOT_ENOUGH_ROOM :
cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
}
else
throw invalid_utf8 (*it);
}
else
throw not_enough_room(); throw not_enough_room();
} case internal::INVALID_LEAD :
else if ((internal::mask8(*it) >> 4) == 0xe) { case internal::INCOMPLETE_SEQUENCE :
if (++it != end) { case internal::OVERLONG_SEQUENCE :
if (internal::is_trail(*it)) { throw invalid_utf8(*it);
cp = ((cp << 12) & 0xffff) + ((internal::mask8(*it) << 6) & 0xfff); case internal::INVALID_CODE_POINT :
if (++it != end) {
if (internal::is_trail(*it)) {
cp += (*it) & 0x3f;
}
else
throw invalid_utf8 (*it);
}
else
throw not_enough_room();
}
else
throw invalid_utf8 (*it);
}
else
throw not_enough_room();
}
else if ((internal::mask8(*it) >> 3) == 0x1e) {
if (++it != end) {
if (internal::is_trail(*it)) {
cp = ((cp << 18) & 0x1fffff) + (internal::mask8(*it) << 12) & 0x3ffff;
if (++it != end) {
if (internal::is_trail(*it)) {
cp += (internal::mask8(*it) << 6) & 0xfff;
if (++it != end) {
if (internal::is_trail(*it)) {
cp += (*it) & 0x3f;
}
else
throw invalid_utf8 (*it);
}
else
throw not_enough_room();
}
else
throw invalid_utf8 (*it);
}
else
throw not_enough_room();
}
else
throw invalid_utf8 (*it);
}
else
throw not_enough_room();
}
++it;
if (cp > internal::CODE_POINT_MAX || internal::is_surrogate(cp))
throw invalid_code_point(cp); throw invalid_code_point(cp);
}
return cp; return cp;
} }