Classes | Macros | Functions | Variables
doxyindexer.cpp File Reference
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <qregexp.h>
#include <qxml.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <xapian.h>

Go to the source code of this file.

Classes

class  XMLContentHandler
 
class  XMLErrorHandler
 

Macros

#define MAX_TERM_LENGTH   245
 

Functions

static void safeAddTerm (const std::string &term, Xapian::Document &doc, int wfd)
 
static std::string trim (const std::string &str, const std::string &whitespace=" \t")
 
static std::string reduce (const std::string &str, const std::string &fill=" ", const std::string &whitespace=" \t")
 
static void addWords (const std::string &s, Xapian::Document &doc, int wfd)
 
static void addIdentifiers (const std::string &s, Xapian::Document &doc, int wfd)
 
static void replace_all (std::string &str, const std::string &old, const std::string &repl)
 
static std::string unescapeXmlEntities (const std::string &s)
 
static void usage (const char *name)
 
int main (int argc, const char **argv)
 

Variables

static char pathSep = '/'
 

Macro Definition Documentation

#define MAX_TERM_LENGTH   245

Definition at line 33 of file doxyindexer.cpp.

Function Documentation

static void addIdentifiers ( const std::string s,
Xapian::Document &  doc,
int  wfd 
)
static

Adds all identifiers in s to document doc with weight wfd

Definition at line 105 of file doxyindexer.cpp.

106 {
107  QRegExp re("[A-Z_a-z][A-Z_a-z0-9]*");
108  int i,l,p=0;
109  QCString qs = s.c_str();
110  while ((i=re.match(qs,p,&l))!=-1)
111  {
112  safeAddTerm(qs.mid(p,i-p).data(),doc,wfd);
113  p=i+l;
114  }
115 }
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
static QStrList * l
Definition: config.cpp:1044
p
Definition: test.py:223
const char * data() const
Definition: qcstring.h:207
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
static void safeAddTerm(const std::string &term, Xapian::Document &doc, int wfd)
Definition: doxyindexer.cpp:41
QCString doc
static QCString * s
Definition: config.cpp:1042
static void addWords ( const std::string s,
Xapian::Document &  doc,
int  wfd 
)
static

Adds all words in s to document doc with weight wfd

Definition at line 87 of file doxyindexer.cpp.

88 {
89  std::istringstream iss(s);
90  std::istream_iterator<std::string> begin(iss),end,it;
91  for (it=begin;it!=end;++it)
92  {
93  std::string word = *it;
94  std::string lword = word;
95  std::transform(lword.begin(), lword.end(), lword.begin(), ::tolower);
96  safeAddTerm(word,doc,wfd);
97  if (lword!=word)
98  {
99  safeAddTerm(lword,doc,wfd);
100  }
101  }
102 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::string string
Definition: nybbler.cc:12
static void safeAddTerm(const std::string &term, Xapian::Document &doc, int wfd)
Definition: doxyindexer.cpp:41
QCString doc
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
static QCString * s
Definition: config.cpp:1042
union ptb::content::word::word word
int main ( int  argc,
const char **  argv 
)

main function to index data

Definition at line 313 of file doxyindexer.cpp.

314 {
315  if (argc<2)
316  {
317  usage(argv[0]);
318  }
319  QString outputDir;
320  for (int i=1;i<argc;i++)
321  {
322  if (std::string(argv[i])=="-o")
323  {
324  if (i>=argc-1)
325  {
326  std::cerr << "Error: missing parameter for -o option" << std::endl;
327  usage(argv[0]);
328  }
329  else
330  {
331  i++;
332  outputDir=argv[i];
333  QFileInfo fi(outputDir);
334  if (!fi.exists() || !fi.isDir())
335  {
336  std::cerr << "Error: specified output directory does not exist!" << std::endl;
337  usage(argv[0]);
338  }
339  }
340  }
341  else if (std::string(argv[i])=="-h" || std::string(argv[i])=="--help")
342  {
343  usage(argv[0]);
344  }
345  }
346 
347  try
348  {
349  if (!outputDir.isEmpty() && outputDir.at(outputDir.length()-1)!=pathSep)
350  {
351  outputDir+=pathSep;
352  }
353  XMLContentHandler handler(outputDir);
354  XMLErrorHandler errorHandler;
355  for (int i=1;i<argc;i++)
356  {
357  if (std::string(argv[i])=="-o")
358  {
359  i++;
360  }
361  else
362  {
363  QString xmlFileName = argv[i];
364  std::cout << "Processing " << xmlFileName.utf8() << "..." << std::endl;
365  QFile xmlFile(xmlFileName);
366  QXmlInputSource source(xmlFile);
367  QXmlSimpleReader reader;
368  reader.setContentHandler(&handler);
369  reader.setErrorHandler(&errorHandler);
370  reader.parse(source);
371  }
372  }
373  }
374  catch(const Xapian::Error &e)
375  {
376  std::cerr << "Caught exception: " << e.get_description() << std::endl;
377  }
378  catch(...)
379  {
380  std::cerr << "Caught an unknown exception" << std::endl;
381  }
382 
383  return 0;
384 }
bool isEmpty() const
Definition: qstring.h:682
std::string string
Definition: nybbler.cc:12
bool parse(const QXmlInputSource &input)
Definition: qxml.cpp:2077
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void setErrorHandler(QXmlErrorHandler *handler)
Definition: qxml.cpp:2051
The QXmlSimpleReader class provides an implementation of a simple XML reader (i.e. parser).
Definition: qxml.h:238
void setContentHandler(QXmlContentHandler *handler)
Definition: qxml.cpp:2043
const double e
QChar at(uint i) const
Definition: qstring.h:492
nvidia::inferenceserver::client::Error Error
Definition: triton_utils.h:15
uint length() const
Definition: qstring.h:679
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
static void usage(const char *name)
static msg_handler handler
Definition: qglobal.cpp:234
The QXmlInputSource class is the source where XML data is read from.
Definition: qxml.h:162
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
QCString utf8() const
Definition: qstring.cpp:14507
QTextStream & endl(QTextStream &s)
static char pathSep
Definition: doxyindexer.cpp:38
static std::string reduce ( const std::string str,
const std::string fill = " ",
const std::string whitespace = " \t" 
)
static

trims whitespace from start and end and replace occurrences of whitespace with fill.

Definition at line 63 of file doxyindexer.cpp.

66 {
67  // trim first
68  std::string result = trim(str, whitespace);
69 
70  // replace sub ranges
71  size_t beginSpace = result.find_first_of(whitespace);
72  while (beginSpace != std::string::npos)
73  {
74  size_t endSpace = result.find_first_not_of(whitespace, beginSpace);
75  int range = endSpace - beginSpace;
76 
77  result.replace(beginSpace, range, fill);
78 
79  size_t newStart = beginSpace + fill.length();
80  beginSpace = result.find_first_of(whitespace, newStart);
81  }
82 
83  return result;
84 }
static std::string trim(const std::string &str, const std::string &whitespace=" \t")
Definition: doxyindexer.cpp:47
static QCString result
std::string string
Definition: nybbler.cc:12
def fill(s)
Definition: translator.py:93
static QCString str
static void replace_all ( std::string str,
const std::string old,
const std::string repl 
)
static

Replaces all occurrences of old with repl in string str

Definition at line 118 of file doxyindexer.cpp.

119 {
120  size_t pos = 0;
121  while ((pos = str.find(old, pos)) != std::string::npos)
122  {
123  str.replace(pos, old.length(), repl);
124  pos += repl.length();
125  }
126 }
uint length() const
Definition: qcstring.h:195
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
QCString & replace(uint index, uint len, const char *s)
Definition: qcstring.cpp:411
static QCString str
static void safeAddTerm ( const std::string term,
Xapian::Document &  doc,
int  wfd 
)
static

Definition at line 41 of file doxyindexer.cpp.

42 {
43  if (term.length()<=MAX_TERM_LENGTH) doc.add_term(term,wfd);
44 }
#define MAX_TERM_LENGTH
Definition: doxyindexer.cpp:33
QCString doc
static std::string trim ( const std::string str,
const std::string whitespace = " \t" 
)
static

trims whitespace characters from the start and end of string str.

Definition at line 47 of file doxyindexer.cpp.

49 {
50  size_t strBegin = str.find_first_not_of(whitespace);
51  if (strBegin == std::string::npos)
52  return ""; // no content
53 
54  size_t strEnd = str.find_last_not_of(whitespace);
55  int strRange = strEnd - strBegin + 1;
56 
57  return str.substr(strBegin, strRange);
58 }
static QCString str
static std::string unescapeXmlEntities ( const std::string s)
static

Replaces all XML entities in s with their unescaped representation

Definition at line 129 of file doxyindexer.cpp.

130 {
132  replace_all(result,"&gt;",">");
133  replace_all(result,"&lt;","<");
134  replace_all(result,"&apos;","'");
135  replace_all(result,"&quot;","\"");
136  replace_all(result,"&amp;","&");
137  return result;
138 }
static void replace_all(std::string &str, const std::string &old, const std::string &repl)
static QCString result
std::string string
Definition: nybbler.cc:12
static QCString * s
Definition: config.cpp:1042
static void usage ( const char *  name)
static

Definition at line 306 of file doxyindexer.cpp.

307 {
308  std::cerr << "Usage: " << name << " [-o output_dir] searchdata.xml [searchdata2.xml ...]" << std::endl;
309  exit(1);
310 }
static QCString name
Definition: declinfo.cpp:673
QTextStream & endl(QTextStream &s)

Variable Documentation

char pathSep = '/'
static

Definition at line 38 of file doxyindexer.cpp.