MCPcopy Create free account
hub / github.com/davisking/dlib / underflow

Method underflow

dlib/unicode/unicode.h:153–200  ·  view source on GitHub ↗

input functions

Source from the content-addressed store, hash-verified

151
152 // input functions
153 int_type underflow(
154 )
155 {
156 if (this->gptr() < this->egptr())
157 {
158 return zero_extend_cast<int_type>(*this->gptr());
159 }
160
161 int num_put_back = static_cast<int>(this->gptr() - this->eback());
162 if (num_put_back > max_putback)
163 {
164 num_put_back = max_putback;
165 }
166
167 // copy the putback characters into the putback end of the in_buffer
168 std::memmove(in_buffer+(max_putback-num_put_back), this->gptr()-num_put_back, num_put_back);
169
170
171 // fill the buffer with characters
172 int n = in_buffer_size-max_putback;
173 int i;
174 for (i = 0; i < n; ++i)
175 {
176 charT ch;
177 using iter_type = std::istreambuf_iterator<char>;
178 if (unicode_helpers::u8_to_u32(ch, iter_type(fin), iter_type()) > 0)
179 {
180 (in_buffer+max_putback)[i] = ch;
181 }
182 else
183 {
184 break;
185 }
186 }
187
188 if (i == 0)
189 {
190 // an error occurred or we hit EOF
191 return EOF;
192 }
193
194 // reset in_buffer pointers
195 this->setg (in_buffer+(max_putback-num_put_back),
196 in_buffer+max_putback,
197 in_buffer+max_putback+i);
198
199 return zero_extend_cast<int_type>(*this->gptr());
200 }
201
202 private:
203 std::ifstream& fin;

Callers

nothing calls this directly

Calls 1

u8_to_u32Function · 0.85

Tested by

no test coverage detected