aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-07 14:12:01 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-10 08:32:56 +0000
commit1bfd77c92d78c3861d0c09068e6c353020a510f4 (patch)
tree48ccb45110bd155df0884be01009b2d7c22fa220 /sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
parentb49d3517e6b82eb40d7deff523cd127ba1348eb8 (diff)
shiboken2/clangparser: Use std::string_view for code snippet extraction
std: :string_view was added in C++ 17 and fits the purpose. Remove some outdated code for Clang < 5 on this occasion. Change-Id: I787f736679421c9080a6cabdef1616efb2c512e9 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp39
1 files changed, 5 insertions, 34 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
index 263c0a0bb..f00b8dc42 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
@@ -574,44 +574,15 @@ void BuilderPrivate::endTemplateTypeAlias(const CXCursor &typeAliasCursor)
// CXCursor_EnumConstantDecl, ParmDecl (a = Flag1 | Flag2)
QString BuilderPrivate::cursorValueExpression(BaseVisitor *bv, const CXCursor &cursor) const
{
- BaseVisitor::CodeSnippet snippet = bv->getCodeSnippet(cursor);
- const char *equalSign = std::find(snippet.first, snippet.second, '=');
- if (equalSign == snippet.second)
+ const std::string_view snippet = bv->getCodeSnippet(cursor);
+ auto equalSign = snippet.find('=');
+ if (equalSign == std::string::npos)
return QString();
++equalSign;
- return QString::fromLocal8Bit(equalSign, int(snippet.second - equalSign)).trimmed();
+ return QString::fromLocal8Bit(snippet.cbegin() + equalSign,
+ int(snippet.size() - equalSign)).trimmed();
}
-// A hacky reimplementation of clang_EnumDecl_isScoped() for Clang < 5.0
-// which simply checks for a blank-delimited " class " keyword in the enum snippet.
-
-#define CLANG_NO_ENUMDECL_ISSCOPED \
- (CINDEX_VERSION_MAJOR == 0 && CINDEX_VERSION_MINOR < 43)
-
-#if CLANG_NO_ENUMDECL_ISSCOPED
-static const char *indexOf(const BaseVisitor::CodeSnippet &snippet, const char *needle)
-{
- const size_t snippetLength = snippet.first ? size_t(snippet.second - snippet.first) : 0;
- const size_t needleLength = strlen(needle);
- if (needleLength > snippetLength)
- return nullptr;
- for (const char *c = snippet.first, *end = snippet.second - needleLength; c < end; ++c) {
- if (memcmp(c, needle, needleLength) == 0)
- return c;
- }
- return nullptr;
-}
-
-long clang_EnumDecl_isScoped4(BaseVisitor *bv, const CXCursor &cursor)
-{
- BaseVisitor::CodeSnippet snippet = bv->getCodeSnippet(cursor);
- const char *classSpec = indexOf(snippet, "class");
- const bool isClass = classSpec && classSpec > snippet.first
- && isspace(*(classSpec - 1)) && isspace(*(classSpec + 5));
- return isClass ? 1 : 0;
-}
-#endif // CLANG_NO_ENUMDECL_ISSCOPED
-
// Resolve declaration and type of a base class
struct TypeDeclaration