diff src/lstream.c @ 5785:7343a186a475

Correct some partial character accounting, buffered_bytecount_to_charcount(). src/ChangeLog addition: 2014-01-23 Aidan Kehoe <kehoea@parhasard.net> * lstream.c (Lstream_read_1): Don't include the unread partial character in unget_character_count, since our consumers will never be aware of it. * text.c: * text.c (buffered_bytecount_to_charcount): A buffer consisting entirely of a partial character needs to be treated as a partial last character, not a partial first character, to avoid double-counting.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 23 Jan 2014 13:49:40 +0000
parents 0cb4f494a548
children d2c0ff38ad5c
line wrap: on
line diff
--- a/src/lstream.c	Wed Jan 22 17:52:00 2014 +0000
+++ b/src/lstream.c	Thu Jan 23 13:49:40 2014 +0000
@@ -721,8 +721,15 @@
       Bytecount newoff = validate_ibyte_string_backward (p, off);
       if (newoff < off)
 	{
+          Charcount before = lstr->unget_character_count;
 	  Lstream_unread (lstr, p + newoff, off - newoff);
 	  off = newoff;
+
+          /* Since it's Lstream_read rather than our consumers unreading the
+             incomplete character (conceptually, not affecting the number of
+             characters ever Lstream_read() from the stream),
+             unget_character_count shouldn't include it. */
+          lstr->unget_character_count = before;
 	}
     }