MCPcopy Create free account
hub / github.com/crawl/crawl / get_line

Method get_line

crawl-ref/source/unicode.cc:307–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307string FileLineInput::get_line()
308{
309 ASSERT(f);
310 vector<utf16_t> win;
311 string out;
312 char buf[512];
313 char32_t c;
314 int len;
315
316 switch (bom)
317 {
318 case BOM_NORMAL:
319 do
320 {
321 if (!fgets(buf, sizeof buf, f))
322 {
323 seen_eof = true;
324 break;
325 }
326 out += buf;
327 if (out[out.length() - 1] == '\n')
328 {
329 out.erase(out.length() - 1);
330 break;
331 }
332 } while (!seen_eof);
333 return mb_to_utf8(out.c_str());
334
335 case BOM_UTF8:
336 do
337 {
338 if (!fgets(buf, sizeof buf, f))
339 {
340 seen_eof = true;
341 break;
342 }
343 out += buf;
344 if (out[out.length() - 1] == '\n')
345 {
346 out.erase(out.length() - 1);
347 break;
348 }
349 } while (!seen_eof);
350 return utf8_validate(out.c_str());
351
352 case BOM_UTF16LE:
353 do
354 {
355 if (fread(buf, 2, 1, f) != 1)
356 {
357 seen_eof = true;
358 break;
359 }
360 c = ((uint32_t)((unsigned char)buf[0]))
361 | ((uint32_t)((unsigned char)buf[1])) << 8;
362 if (c == '\n')
363 break;
364 win.push_back(c);

Callers 6

_parse_from_fileMethod · 0.45
read_optionsMethod · 0.45
_read_macros_fromFunction · 0.45
_parse_text_dbFunction · 0.45
load_persistMethod · 0.45
loadfileMethod · 0.45

Calls 7

wctoutf8Function · 0.85
mb_to_utf8Function · 0.70
utf8_validateFunction · 0.70
utf16_to_8Function · 0.70
dieFunction · 0.70
eraseMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected