mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-23 23:16:39 +01:00
Merge pull request #4027 from Crafty-Codes/fix/function-parameter
CppParser: fix for std::function<void()> parameter
This commit is contained in:
commit
6356cd22ad
@ -121,6 +121,29 @@ std::string Symbol::extractName(const std::string& decl)
|
||||
return "operator []";
|
||||
|
||||
std::string::size_type pos = decl.find('(');
|
||||
if (pos != std::string::npos) {
|
||||
// special case std::function<void(int)> a
|
||||
// ^ ^^
|
||||
// In case the marked patterns are found,
|
||||
// reset pos to npos to make sure "(" is not seen as the beginning of a function
|
||||
int bracket = 1;
|
||||
std::string::size_type i = pos + 1;
|
||||
while (i < decl.size() && bracket != 0){
|
||||
if (decl[i] == '('){
|
||||
bracket++;
|
||||
} else if (decl[i] == ')'){
|
||||
bracket--;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
while (i < decl.size() && std::isspace(decl[i])) i++;
|
||||
if (i < decl.size() && decl[i] == '>') {
|
||||
pos = std::string::npos;
|
||||
}
|
||||
}
|
||||
|
||||
// another special case: function pointer
|
||||
if (pos != std::string::npos && pos < decl.size() - 1)
|
||||
{
|
||||
|
@ -77,6 +77,22 @@ void CppParserTest::testExtractName()
|
||||
decl = "void func(int arg1, int arg2)";
|
||||
name = Symbol::extractName(decl);
|
||||
assertTrue (name == "func");
|
||||
|
||||
decl = "std::function<bool> func";
|
||||
name = Symbol::extractName(decl);
|
||||
assertTrue (name == "func");
|
||||
|
||||
decl = "std::function<void(bool)> func";
|
||||
name = Symbol::extractName(decl);
|
||||
assertTrue (name == "func");
|
||||
|
||||
decl = "std::function<std::vector<int>(std::vector<bool>)> func";
|
||||
name = Symbol::extractName(decl);
|
||||
assertTrue (name == "func");
|
||||
|
||||
decl = "std::function<void*(std::function<const int*(void)>)> func";
|
||||
name = Symbol::extractName(decl);
|
||||
assertTrue (name == "func");
|
||||
|
||||
decl = "const std::vector<NS::MyType>* var";
|
||||
name = Symbol::extractName(decl);
|
||||
|
Loading…
x
Reference in New Issue
Block a user