Jump to: navigation, search


1,001 bytes added, 19:33, 21 January 2010
Finding articles
std::string stringdata = std::string(, blob.size());
const char* zptr = stringdata.c_str(); // c_str() guarantees, that the pointer points to zero terminated data
''find'' and ''findByTitle'' return the lexicographically next article. If you whan to know, if you really got exactly the article you requested, you may either compare the url (or title) to the parameter or use ''findx'' or ''findxByTitle''. Both return a std::pair, with the first element a bool, which is true, if a exact match was found and false otherwise. The second element is the actual iterator, as returned by ''find'' or ''findByTitle''. The latter are actually only wrappers around the ''findx''-methods throwing away the flag. If the flag is true, the iterator does point to a article. It is not necessary to check against end() any more.
;Sample: find the exact article by url
<source lang=c>
std::pair<bool, zim::File::const_iterator> it = file.findxByTitle('A', "Wikipedia");
if (!it.first)
throw std::runtime_error("article not found");
if (it->isRedirect())
std::cout << "see: " << it->getRedirectArticle().getTitle() << std::endl;
std::cout << it->getData();

Navigation menu