| 368 | } |
| 369 | |
| 370 | std::optional<uint16_t> Section::getPageForAnchor(const std::string& anchor) const { |
| 371 | HalFile f; |
| 372 | if (!Storage.openFileForRead("SCT", filePath, f)) { |
| 373 | return std::nullopt; |
| 374 | } |
| 375 | |
| 376 | const uint32_t fileSize = f.size(); |
| 377 | f.seek(HEADER_SIZE - sizeof(uint32_t) * 3); |
| 378 | uint32_t anchorMapOffset; |
| 379 | serialization::readPod(f, anchorMapOffset); |
| 380 | if (anchorMapOffset == 0 || anchorMapOffset >= fileSize) { |
| 381 | return std::nullopt; |
| 382 | } |
| 383 | |
| 384 | f.seek(anchorMapOffset); |
| 385 | uint16_t count; |
| 386 | serialization::readPod(f, count); |
| 387 | for (uint16_t i = 0; i < count; i++) { |
| 388 | std::string key; |
| 389 | uint16_t page; |
| 390 | serialization::readString(f, key); |
| 391 | serialization::readPod(f, page); |
| 392 | if (key == anchor) { |
| 393 | return page; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return std::nullopt; |
| 398 | } |
| 399 | |
| 400 | std::optional<uint16_t> Section::getPageForParagraphIndex(const uint16_t pIndex) const { |
| 401 | HalFile f; |
no test coverage detected