| 398 | } |
| 399 | |
| 400 | std::optional<uint16_t> Section::getPageForParagraphIndex(const uint16_t pIndex) const { |
| 401 | HalFile f; |
| 402 | if (!Storage.openFileForRead("SCT", filePath, f)) { |
| 403 | return std::nullopt; |
| 404 | } |
| 405 | |
| 406 | const uint32_t fileSize = f.size(); |
| 407 | f.seek(HEADER_SIZE - sizeof(uint32_t) * 2); |
| 408 | uint32_t paragraphLutOffset; |
| 409 | serialization::readPod(f, paragraphLutOffset); |
| 410 | if (paragraphLutOffset == 0 || paragraphLutOffset >= fileSize) { |
| 411 | return std::nullopt; |
| 412 | } |
| 413 | |
| 414 | f.seek(paragraphLutOffset); |
| 415 | uint16_t count; |
| 416 | serialization::readPod(f, count); |
| 417 | if (count == 0) { |
| 418 | return std::nullopt; |
| 419 | } |
| 420 | |
| 421 | const uint32_t lutEnd = paragraphLutOffset + sizeof(uint16_t) + count * sizeof(uint16_t); |
| 422 | if (lutEnd > fileSize) { |
| 423 | return std::nullopt; |
| 424 | } |
| 425 | |
| 426 | uint16_t resultPage = count - 1; |
| 427 | for (uint16_t i = 0; i < count; i++) { |
| 428 | uint16_t pagePIdx; |
| 429 | serialization::readPod(f, pagePIdx); |
| 430 | if (pagePIdx >= pIndex) { |
| 431 | resultPage = i; |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | return resultPage; |
| 437 | } |
| 438 | |
| 439 | std::optional<uint16_t> Section::getParagraphIndexForPage(const uint16_t page) const { |
| 440 | HalFile f; |
no test coverage detected