Skip to content

Commit

Permalink
Update utfcpp to v2.3.6
Browse files Browse the repository at this point in the history
Fixes sass#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
  • Loading branch information
glebm authored and xzyfer committed Nov 28, 2018
1 parent b09e813 commit 2cabd11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/utf8/checked.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2006 Nemanja Trifunovic
// Copyright 2006-2016 Nemanja Trifunovic

/*
Permission is hereby granted, free of charge, to any person or organization
Expand Down Expand Up @@ -41,7 +41,7 @@ namespace utf8
class invalid_code_point : public exception {
uint32_t cp;
public:
invalid_code_point(uint32_t cp) : cp(cp) {}
invalid_code_point(uint32_t codepoint) : cp(codepoint) {}
virtual const char* what() const throw() { return "Invalid code point"; }
uint32_t code_point() const {return cp;}
};
Expand Down Expand Up @@ -107,7 +107,9 @@ namespace utf8
*out++ = *it;
break;
case internal::NOT_ENOUGH_ROOM:
throw not_enough_room();
out = utf8::append (replacement, out);
start = end;
break;
case internal::INVALID_LEAD:
out = utf8::append (replacement, out);
++start;
Expand Down Expand Up @@ -194,10 +196,10 @@ namespace utf8
}

template <typename octet_iterator, typename distance_type>
void retreat (octet_iterator& it, distance_type n, octet_iterator start)
void retreat (octet_iterator& it, distance_type n, octet_iterator end)
{
for (distance_type i = 0; i < n; ++i)
utf8::prior(it, start);
utf8::prior(it, end);
}

template <typename octet_iterator>
Expand Down Expand Up @@ -240,7 +242,7 @@ namespace utf8
template <typename u16bit_iterator, typename octet_iterator>
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);
if (cp > 0xffff) { //make a surrogate pair
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
Expand All @@ -264,7 +266,7 @@ namespace utf8
template <typename octet_iterator, typename u32bit_iterator>
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
{
while (start != end)
while (start < end)
(*result++) = utf8::next(start, end);

return result;
Expand All @@ -279,9 +281,9 @@ namespace utf8
public:
iterator () {}
explicit iterator (const octet_iterator& octet_it,
const octet_iterator& range_start,
const octet_iterator& range_end) :
it(octet_it), range_start(range_start), range_end(range_end)
const octet_iterator& rangestart,
const octet_iterator& rangeend) :
it(octet_it), range_start(rangestart), range_end(rangeend)
{
if (it < range_start || it > range_end)
throw std::out_of_range("Invalid utf-8 iterator position");
Expand Down
3 changes: 3 additions & 0 deletions src/utf8/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ namespace internal
template <typename octet_iterator>
utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
{
if (it == end)
return NOT_ENOUGH_ROOM;

// Save the original value of it so we can go back in case of failure
// Of course, it does not make much sense with i.e. stream iterators
octet_iterator original_it = it;
Expand Down

0 comments on commit 2cabd11

Please sign in to comment.