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

Method resolveHrefToSpineIndex

lib/Epub/Epub.cpp:902–927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

900}
901
902int Epub::resolveHrefToSpineIndex(const std::string& href) const {
903 if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return -1;
904
905 // Split before decoding so escaped '#' characters in filenames stay part of the path.
906 const size_t hashPos = href.find('#');
907 const std::string rawTarget = hashPos != std::string::npos ? href.substr(0, hashPos) : href;
908 const std::string target = FsHelpers::normalisePath(FsHelpers::decodeUriEscapes(rawTarget));
909
910 // Same-file reference (anchor-only)
911 if (target.empty()) return -1;
912
913 // Extract just the filename for comparison
914 size_t targetSlash = target.find_last_of('/');
915 std::string targetFilename = (targetSlash != std::string::npos) ? target.substr(targetSlash + 1) : target;
916
917 for (int i = 0; i < getSpineItemsCount(); i++) {
918 const auto& spineHref = getSpineItem(i).href;
919 // Try exact match first
920 if (spineHref == target) return i;
921 // Then filename-only match
922 size_t spineSlash = spineHref.find_last_of('/');
923 std::string spineFilename = (spineSlash != std::string::npos) ? spineHref.substr(spineSlash + 1) : spineHref;
924 if (spineFilename == targetFilename) return i;
925 }
926 return -1;
927}

Callers 1

navigateToHrefMethod · 0.80

Calls 4

normalisePathFunction · 0.85
decodeUriEscapesFunction · 0.85
isLoadedMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected