getPotentialFunctionNames static method
Detect potential function names
This method analyzes the given string and assumes if there are any function names. This method doesn't give you a 100% guarantee if you use implicit multiplication, since there's no way to be sure if an unprocessed substring is a function name or a variable being multiplied. Because of that, this method assumes you don't use implicit multiplication.
Returns a list of strings of potential undeclared function names.
Use hideBuiltIns
if you want to remove built-in functions like cos
,
sin
and other from result. Can be useful if you are going to prompt user
to define the functions.
Implementation
static Set<String> getPotentialFunctionNames(
String expression, {
bool hideBuiltIns = false,
}) {
return RegExp('(' + _variableNameBaseRegExp + ')([(])')
.allMatches(expression)
.map((element) => element.group(1)!)
.where((element) {
return (!hideBuiltIns || !_bracketFuncs.contains(element));
}).toSet();
}