Skip to content

Commit

Permalink
Fix #5712
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Jun 20, 2014
1 parent 5525ab8 commit 9ae4c94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/support/ios.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,15 +979,15 @@ int ios_getutf8(ios_t *s, uint32_t *pwc)
*pwc = (uint32_t)(unsigned char)c0;
return 1;
}
sz = u8_seqlen(&c0)-1;
sz = u8_seqlen(&c0);
if (ios_ungetc(c, s) == IOS_EOF)
return IOS_EOF;
if (ios_readprep(s, sz) < sz)
// NOTE: this can return EOF even if some bytes are available
return IOS_EOF;
size_t i = s->bpos;
*pwc = u8_nextchar(s->buf, &i);
ios_read(s, buf, sz+1);
ios_read(s, buf, sz);
return 1;
}

Expand All @@ -1005,7 +1005,7 @@ int ios_peekutf8(ios_t *s, uint32_t *pwc)
*pwc = (uint32_t)(unsigned char)c0;
return 1;
}
sz = u8_seqlen(&c0)-1;
sz = u8_seqlen(&c0);
if (ios_readprep(s, sz) < sz)
return IOS_EOF;
size_t i = s->bpos;
Expand Down
22 changes: 6 additions & 16 deletions src/support/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ size_t u8_strwidth(const char *s)
uint32_t u8_nextchar(const char *s, size_t *i)
{
uint32_t ch = 0;
size_t sz = 0;
size_t sz, j;

do {
sz = u8_seqlen(&s[*i]);
for (j = sz; j > 0; j--) {
ch <<= 6;
ch += (unsigned char)s[(*i)];
sz++;
} while (s[*i] && (++(*i)) && !isutf(s[*i]));
ch += (unsigned char)s[(*i)++];
}
ch -= offsetsFromUTF8[sz-1];

return ch;
Expand All @@ -319,17 +319,7 @@ uint32_t u8_nextchar(const char *s, size_t *i)
/* next character without NUL character terminator */
uint32_t u8_nextmemchar(const char *s, size_t *i)
{
uint32_t ch = 0;
size_t sz = 0;

do {
ch <<= 6;
ch += (unsigned char)s[(*i)++];
sz++;
} while (!isutf(s[*i]));
ch -= offsetsFromUTF8[sz-1];

return ch;
return u8_nextchar(s,i);
}

void u8_inc(const char *s, size_t *i)
Expand Down

3 comments on commit 9ae4c94

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bravo!

@jiahao
Copy link
Member

@jiahao jiahao commented on 9ae4c94 Jun 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☃ = ☺︎

Please sign in to comment.