Skip to content

Commit 2cabd11

Browse files
glebmxzyfer
authored andcommitted
Update utfcpp to v2.3.6
Fixes #2657 Incorporates the following utfcpp patches: 1. Sass addition of `retreat`. nemtrif/utfcpp#20 2. Fix for `replace_invalid` throwing on incomplete sequence at the end of the input. nemtrif/utfcpp#21
1 parent b09e813 commit 2cabd11

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/utf8/checked.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2006 Nemanja Trifunovic
1+
// Copyright 2006-2016 Nemanja Trifunovic
22

33
/*
44
Permission is hereby granted, free of charge, to any person or organization
@@ -41,7 +41,7 @@ namespace utf8
4141
class invalid_code_point : public exception {
4242
uint32_t cp;
4343
public:
44-
invalid_code_point(uint32_t cp) : cp(cp) {}
44+
invalid_code_point(uint32_t codepoint) : cp(codepoint) {}
4545
virtual const char* what() const throw() { return "Invalid code point"; }
4646
uint32_t code_point() const {return cp;}
4747
};
@@ -107,7 +107,9 @@ namespace utf8
107107
*out++ = *it;
108108
break;
109109
case internal::NOT_ENOUGH_ROOM:
110-
throw not_enough_room();
110+
out = utf8::append (replacement, out);
111+
start = end;
112+
break;
111113
case internal::INVALID_LEAD:
112114
out = utf8::append (replacement, out);
113115
++start;
@@ -194,10 +196,10 @@ namespace utf8
194196
}
195197

196198
template <typename octet_iterator, typename distance_type>
197-
void retreat (octet_iterator& it, distance_type n, octet_iterator start)
199+
void retreat (octet_iterator& it, distance_type n, octet_iterator end)
198200
{
199201
for (distance_type i = 0; i < n; ++i)
200-
utf8::prior(it, start);
202+
utf8::prior(it, end);
201203
}
202204

203205
template <typename octet_iterator>
@@ -240,7 +242,7 @@ namespace utf8
240242
template <typename u16bit_iterator, typename octet_iterator>
241243
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
242244
{
243-
while (start != end) {
245+
while (start < end) {
244246
uint32_t cp = utf8::next(start, end);
245247
if (cp > 0xffff) { //make a surrogate pair
246248
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
@@ -264,7 +266,7 @@ namespace utf8
264266
template <typename octet_iterator, typename u32bit_iterator>
265267
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
266268
{
267-
while (start != end)
269+
while (start < end)
268270
(*result++) = utf8::next(start, end);
269271

270272
return result;
@@ -279,9 +281,9 @@ namespace utf8
279281
public:
280282
iterator () {}
281283
explicit iterator (const octet_iterator& octet_it,
282-
const octet_iterator& range_start,
283-
const octet_iterator& range_end) :
284-
it(octet_it), range_start(range_start), range_end(range_end)
284+
const octet_iterator& rangestart,
285+
const octet_iterator& rangeend) :
286+
it(octet_it), range_start(rangestart), range_end(rangeend)
285287
{
286288
if (it < range_start || it > range_end)
287289
throw std::out_of_range("Invalid utf-8 iterator position");

src/utf8/core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ namespace internal
222222
template <typename octet_iterator>
223223
utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
224224
{
225+
if (it == end)
226+
return NOT_ENOUGH_ROOM;
227+
225228
// Save the original value of it so we can go back in case of failure
226229
// Of course, it does not make much sense with i.e. stream iterators
227230
octet_iterator original_it = it;

0 commit comments

Comments
 (0)