Try to match function pointers before regular parameters. Function pointers may contain regular parameters themselves and going the other way round will result in incorrect matches.

This commit is contained in:
the_fiddler 2009-08-11 18:51:19 +00:00
parent 33970774a0
commit 6c59478446

View file

@ -190,18 +190,19 @@ namespace CHeaderToXML
string funcname = null;
GetFunctionNameAndType(words, out funcname, out rettype);
if (funcname == "BufferData")
if (funcname == "CreateContextFromType")
Debugger.Break();
var paramaters_string = Regex.Match(line, @"\(.*\)").Captures[0].Value.TrimStart('(').TrimEnd(')');
// This regex matches function parameters. The first part (before the '|') matches parameters of the following formats:
// '[return type] [parameter name]', '[return type] * [parameter name]', 'const [return type]* [parameter name]'
// where [parameter name] can either be inside comments (/* ... */) or not.
// The second part matches functions pointers in the following format:
// This regex matches function parameters.
// The first part matches functions pointers in the following format:
// '[return type] (*[function pointer name])([parameter list]) [parameter name]
// where [parameter name] may or may not be in comments.
var get_param = new Regex(@"((const\s)?\w+\s*\**\s*(/\*.*?\*/|\w+(\[.*?\])?) | \w+\s\(\*\w+\)\(.*\)\s*(/\*.*?\*/|\w+)),?", RegexOptions.IgnorePatternWhitespace);
// The second part (before the '|') matches parameters of the following formats:
// '[return type] [parameter name]', '[return type] * [parameter name]', 'const [return type]* [parameter name]'
// where [parameter name] can either be inside comments (/* ... */) or not.
var get_param = new Regex(@"(\w+\s\(\*\w+\)\s*\(.*\)\s*(/\*.*?\*/|\w+) | (const\s)?\w+\s*\**\s*(/\*.*?\*/|\w+(\[.*?\])?)),?", RegexOptions.IgnorePatternWhitespace);
var ars = get_param.Matches(paramaters_string).OfType<Match>().Select(m => m.Captures[0].Value.TrimEnd(','));