Skip to content

Commit b2ecb97

Browse files
committed
Merge branch 'master' of github.com:doxygen/doxygen
2 parents 4e05eb0 + 12700b4 commit b2ecb97

File tree

4 files changed

+68
-85
lines changed

4 files changed

+68
-85
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ updates:
33
- package-ecosystem: "github-actions"
44
directory: "/"
55
schedule:
6-
interval: "weekly"
6+
interval: "daily"
7+
time: "03:00"
8+
open-pull-requests-limit: 3

addon/doxyparse/doxyparse.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*
1919
*/
2020

21-
#include <stdlib.h>
2221
#if !defined(_WIN32) || defined(__CYGWIN__)
2322
#include <unistd.h>
2423
#else
@@ -41,6 +40,8 @@
4140
#include <cstdlib>
4241
#include <sstream>
4342
#include <map>
43+
#include <algorithm>
44+
#include <filesystem>
4445
#include "qcstring.h"
4546
#include "namespacedef.h"
4647
#include "portable.h"
@@ -114,21 +115,11 @@ static void findXRefSymbols(FileDef *fd)
114115
}
115116

116117
static bool ignoreStaticExternalCall(const MemberDef *context, const MemberDef *md) {
117-
if (md->isStatic()) {
118-
if(md->getFileDef() && context->getFileDef()) {
119-
if(md->getFileDef()->getOutputFileBase() == context->getFileDef()->getOutputFileBase())
120-
// TODO ignore prefix of file
121-
return false;
122-
else
123-
return true;
124-
}
125-
else {
126-
return false;
127-
}
128-
}
129-
else {
130-
return false;
131-
}
118+
if (!md->isStatic()) return false;
119+
if (!md->getFileDef() || !context->getFileDef()) return false;
120+
121+
// TODO ignore prefix of file
122+
return md->getFileDef()->getOutputFileBase() != context->getFileDef()->getOutputFileBase();
132123
}
133124

134125
static void startYamlDocument() {
@@ -185,11 +176,13 @@ static int isPartOfCStruct(const MemberDef * md) {
185176
return is_c_code && md->getClassDef() != nullptr;
186177
}
187178

188-
std::string sanitizeString(std::string data) {
189-
QCString new_data = QCString(data.c_str());
190-
new_data = substitute(new_data,"\"", "");
191-
new_data = substitute(new_data,"\'", ""); // https://github.com/analizo/analizo/issues/138
192-
return !new_data.isEmpty() ? new_data.data() : "";
179+
[[nodiscard]] std::string sanitizeString(std::string data)
180+
{
181+
data.erase(std::remove_if(data.begin(), data.end(), [](unsigned char c) {
182+
return c == '"' || c == '\'';
183+
}),
184+
data.end());
185+
return data;
193186
}
194187

195188
std::string argumentData(const Argument &argument) {
@@ -536,9 +529,7 @@ int main(int argc,char **argv) {
536529
startYamlDocument();
537530
listSymbols();
538531

539-
std::string cleanup_command = "rm -rf ";
540-
cleanup_command += tmpdir.str();
541-
(void)system(cleanup_command.c_str());
542-
543-
exit(0);
532+
std::error_code ec;
533+
std::filesystem::remove_all(tmpdir.str(), ec);
534+
return 0;
544535
}

addon/doxysearch/doxyindexer.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#include <fstream>
2323
#include <iterator>
2424
#include <regex>
25+
#include <filesystem>
26+
#include <unordered_map>
2527

26-
#include <sys/stat.h>
2728

2829
// Xapian include
2930
#include <xapian.h>
@@ -104,7 +105,7 @@ static void addWords(const std::string &s,Xapian::Document &doc,int wfd)
104105
/** Adds all identifiers in \a s to document \a doc with weight \a wfd */
105106
static void addIdentifiers(const std::string &s,Xapian::Document &doc,int wfd)
106107
{
107-
std::regex id_re("[A-Z_a-z][A-Z_a-z0-9]*");
108+
static const std::regex id_re("[A-Z_a-z][A-Z_a-z0-9]*");
108109
auto id_begin = std::sregex_iterator(s.begin(), s.end(), id_re);
109110
auto id_end = std::sregex_iterator();
110111

@@ -176,18 +177,21 @@ class XMLContentHandler
176177
void startElement(const std::string &name, const XMLHandlers::Attributes &attrib)
177178
{
178179
m_data="";
179-
if (name=="field")
180-
{
181-
std::string fieldName = XMLHandlers::value(attrib,"name");
182-
if (fieldName=="type") m_curFieldName=TypeField;
183-
else if (fieldName=="name") m_curFieldName=NameField;
184-
else if (fieldName=="args") m_curFieldName=ArgsField;
185-
else if (fieldName=="tag") m_curFieldName=TagField;
186-
else if (fieldName=="url") m_curFieldName=UrlField;
187-
else if (fieldName=="keywords") m_curFieldName=KeywordField;
188-
else if (fieldName=="text") m_curFieldName=TextField;
189-
else m_curFieldName=UnknownField;
190-
}
180+
181+
if (name != "field") return;
182+
183+
static const std::unordered_map<std::string, FieldNames> fieldMap{
184+
{ "type", TypeField },
185+
{ "name", NameField },
186+
{ "args", ArgsField },
187+
{ "tag", TagField },
188+
{ "url", UrlField },
189+
{ "keywords", KeywordField },
190+
{ "text", TextField }
191+
};
192+
std::string fieldName = XMLHandlers::value(attrib, "name");
193+
auto it = fieldMap.find(fieldName);
194+
m_curFieldName = (it != fieldMap.end()) ? it->second : UnknownField;
191195
}
192196

193197
/** Handler for an end tag. Called for `</doc>` and `</field>` tags */
@@ -292,7 +296,9 @@ inline std::string fileToString(const std::string &fileName)
292296
std::ifstream t(fileName);
293297
std::string result;
294298
t.seekg(0, std::ios::end);
295-
result.reserve(t.tellg());
299+
auto size = t.tellg();
300+
if (size < 0) size = 0;
301+
result.reserve(static_cast<std::size_t>(size));
296302
t.seekg(0, std::ios::beg);
297303
result.assign(std::istreambuf_iterator<char>(t),
298304
std::istreambuf_iterator<char>());
@@ -301,8 +307,8 @@ inline std::string fileToString(const std::string &fileName)
301307

302308
bool dirExists(const char *path)
303309
{
304-
struct stat info = {};
305-
return stat(path,&info)==0 && (info.st_mode&S_IFDIR);
310+
std::error_code ec;
311+
return std::filesystem::is_directory(path, ec);
306312
}
307313

308314
/** main function to index data */
@@ -315,7 +321,8 @@ int main(int argc,const char **argv)
315321
std::string outputDir;
316322
for (int i=1;i<argc;i++)
317323
{
318-
if (std::string(argv[i])=="-o")
324+
const std::string arg{ argv[i] };
325+
if (arg == "-o")
319326
{
320327
if (i>=argc-1)
321328
{
@@ -333,11 +340,11 @@ int main(int argc,const char **argv)
333340
}
334341
}
335342
}
336-
else if (std::string(argv[i])=="-h" || std::string(argv[i])=="--help")
343+
else if (arg == "-h" || arg == "--help")
337344
{
338345
usage(argv[0],0);
339346
}
340-
else if (std::string(argv[i])=="-v" || std::string(argv[i])=="--version")
347+
else if (arg == "-v" || arg == "--version")
341348
{
342349
std::cerr << argv[0] << " version: " << getFullVersion() << std::endl;
343350
exit(0);

addon/doxysearch/doxysearch.cpp

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,37 @@
2020
#include <vector>
2121
#include <sstream>
2222
#include <iostream>
23-
#include <fstream>
2423
#include <string>
2524
#include <algorithm>
25+
#include <filesystem>
2626

2727
// Xapian includes
2828
#include <xapian.h>
2929

3030
#include "version.h"
3131

32-
#ifdef _WIN32
33-
#include <windows.h>
34-
#else
35-
#include <sys/stat.h>
36-
#endif
37-
38-
#define FIELD_TYPE 1
39-
#define FIELD_NAME 2
40-
#define FIELD_ARGS 3
41-
#define FIELD_TAG 4
42-
#define FIELD_URL 5
43-
#define FIELD_KEYW 6
44-
#define FIELD_DOC 7
4532

46-
#define HEX2DEC(x) (((x)>='0' && (x)<='9')?((x)-'0'):\
47-
((x)>='a' && (x)<='f')?((x)-'a'+10):\
48-
((x)>='A' && (x)<='F')?((x)-'A'+10):-1)
33+
constexpr Xapian::valueno FIELD_TYPE{ 1 };
34+
constexpr Xapian::valueno FIELD_NAME{ 2 };
35+
constexpr Xapian::valueno FIELD_ARGS{ 3 };
36+
constexpr Xapian::valueno FIELD_TAG{ 4 };
37+
constexpr Xapian::valueno FIELD_URL{ 5 };
38+
constexpr Xapian::valueno FIELD_KEYW{ 6 };
39+
constexpr Xapian::valueno FIELD_DOC{ 7 };
4940

50-
51-
bool dirExists(const std::string& dirName)
41+
constexpr int hex2dec(unsigned char c)
5242
{
53-
#ifdef _WIN32
54-
DWORD ftyp = GetFileAttributesA(dirName.c_str());
55-
if (ftyp == INVALID_FILE_ATTRIBUTES)
56-
return false; //something is wrong with your path!
57-
58-
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
59-
return true; // this is a directory!
60-
#else
61-
struct stat sb;
43+
if (c >= '0' && c <= '9') return c - '0';
44+
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
45+
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
46+
return -1;
47+
}
6248

63-
if (stat(dirName.c_str(), &sb)==0 && S_ISDIR(sb.st_mode))
64-
{
65-
return true;
66-
}
67-
#endif
6849

69-
return false;
50+
bool dirExists(const std::string &dirname)
51+
{
52+
std::error_code ec;
53+
return std::filesystem::is_directory(dirname, ec);
7054
}
7155

7256

@@ -90,11 +74,10 @@ static std::string uriDecode(const std::string & sSrc)
9074
{
9175
if (*pSrc == '%') // replace %2A with corresponding ASCII character
9276
{
93-
char dec1, dec2;
77+
int dec1, dec2;
9478
unsigned char c1=*(pSrc+1);
9579
unsigned char c2=*(pSrc+2);
96-
if (-1 != (dec1 = HEX2DEC(c1))
97-
&& -1 != (dec2 = HEX2DEC(c2)))
80+
if (-1 != (dec1 = hex2dec(c1)) && -1 != (dec2 = hex2dec(c2)))
9881
{
9982
*pEnd++ = (dec1 << 4) + dec2;
10083
pSrc += 3;
@@ -359,7 +342,7 @@ int main(int argc,char **argv)
359342
std::cout << "Content-Type:application/javascript;charset=utf-8\r\n\n";
360343
// parse query string
361344
std::vector<std::string> parts = split(queryString,'&');
362-
std::string searchFor,callback;
345+
std::string searchFor;
363346
int num=1,page=0;
364347
for (std::vector<std::string>::const_iterator it=parts.begin();it!=parts.end();++it)
365348
{

0 commit comments

Comments
 (0)