From 39ad3313dfeb366881cf82e66e328ad5b7b9c2bd Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sun, 2 Oct 2016 17:16:39 +0200 Subject: [PATCH] Add Reader::urlExists --- src/common/kiwix/reader.cpp | 9 +++++++++ src/common/kiwix/reader.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index d64613fb..395ad5e1 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -511,6 +511,15 @@ namespace kiwix { return retVal; } + /* Check if an article exists */ + bool Reader::urlExists(const string &url) { + char ns = 0; + string titleStr; + this->parseUrl(url, &ns, titleStr); + zim::File::const_iterator findItr = zimFileHandler->find(ns, titleStr); + return findItr->getUrl() == titleStr; + } + /* Search titles by prefix */ bool Reader::searchSuggestions(const string &prefix, unsigned int suggestionsCount, const bool reset) { bool retVal = false; diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index 8e0e3a79..c24648d8 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -71,6 +71,7 @@ namespace kiwix { bool getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); bool searchSuggestions(const string &prefix, unsigned int suggestionsCount, const bool reset = true); bool searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount); + bool urlExists(const string &url); std::vector getTitleVariants(const std::string &title); bool getNextSuggestion(string &title); bool getNextSuggestion(string &title, string &url);