Fixing a potential problem with utf8 to utf16/32 conversions
git-svn-id: http://svn.code.sf.net/p/utfcpp/code@135 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
parent
44cf4dd0f1
commit
86a06ff955
1 changed files with 2 additions and 2 deletions
|
@ -233,7 +233,7 @@ namespace utf8
|
||||||
template <typename u16bit_iterator, typename octet_iterator>
|
template <typename u16bit_iterator, typename octet_iterator>
|
||||||
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
|
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
|
||||||
{
|
{
|
||||||
while (start != end) {
|
while (start < end) {
|
||||||
uint32_t cp = utf8::next(start, end);
|
uint32_t cp = utf8::next(start, end);
|
||||||
if (cp > 0xffff) { //make a surrogate pair
|
if (cp > 0xffff) { //make a surrogate pair
|
||||||
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
|
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
|
||||||
|
@ -257,7 +257,7 @@ namespace utf8
|
||||||
template <typename octet_iterator, typename u32bit_iterator>
|
template <typename octet_iterator, typename u32bit_iterator>
|
||||||
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
|
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
|
||||||
{
|
{
|
||||||
while (start != end)
|
while (start < end)
|
||||||
(*result++) = utf8::next(start, end);
|
(*result++) = utf8::next(start, end);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue