MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / getPageForAnchor

Method getPageForAnchor

lib/Epub/Epub/Section.cpp:370–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368}
369
370std::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
400std::optional<uint16_t> Section::getPageForParagraphIndex(const uint16_t pIndex) const {
401 HalFile f;

Callers 2

toCrossPointMethod · 0.80
renderMethod · 0.80

Calls 5

readPodFunction · 0.85
readStringFunction · 0.85
openFileForReadMethod · 0.80
seekMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected