@@ -30,11 +30,6 @@ template <typename T> class StringConverter {
3030 // # of pops we are allowed to perform (essentially size of the dest buffer)
3131 size_t num_to_write;
3232
33- // on the very first pop, we need to make sure that we always
34- // pushFullCharacter in case a previous StringConverter pushed part of a
35- // character to the mbstate
36- bool first_pop;
37-
3833 ErrorOr<size_t > pushFullCharacter () {
3934 size_t num_pushed;
4035 for (num_pushed = 0 ; !cr.isFull () && src_idx + num_pushed < src_len;
@@ -56,14 +51,12 @@ template <typename T> class StringConverter {
5651public:
5752 StringConverter (const T *s, mbstate *ps, size_t dstlen,
5853 size_t srclen = SIZE_MAX)
59- : cr(ps), src(s), src_len(srclen), src_idx(0 ), num_to_write(dstlen),
60- first_pop (true ) {}
54+ : cr(ps), src(s), src_len(srclen), src_idx(0 ), num_to_write(dstlen) {}
6155
6256 // TODO: following functions are almost identical
6357 // look into templating CharacterConverter pop functions
6458 ErrorOr<char32_t > popUTF32 () {
65- if (cr.isEmpty () || first_pop) {
66- first_pop = false ;
59+ if (cr.isEmpty () || src_idx == 0 ) {
6760 auto src_elements_read = pushFullCharacter ();
6861 if (!src_elements_read.has_value ())
6962 return Error (src_elements_read.error ());
@@ -86,8 +79,7 @@ template <typename T> class StringConverter {
8679 }
8780
8881 ErrorOr<char8_t > popUTF8 () {
89- if (cr.isEmpty () || first_pop) {
90- first_pop = false ;
82+ if (cr.isEmpty () || src_idx == 0 ) {
9183 auto src_elements_read = pushFullCharacter ();
9284 if (!src_elements_read.has_value ())
9385 return Error (src_elements_read.error ());
0 commit comments