| 305 | } |
| 306 | |
| 307 | string 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); |
no test coverage detected