Skip to content

Commit

Permalink
MAT-8075 handle function names and data type having space and comma
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu committed Dec 31, 2024
1 parent 9d75717 commit 42b18ae
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ export interface FunctionProps {

const getArgumentNames = (logic: string): FunctionArgument[] => {
const args = logic.substring(logic.indexOf("(") + 1, logic.indexOf(")"));
const argstr = args.split(",");
return argstr.map((arg) => {
if (arg[0] === " ") {
arg = arg.substring(1);
}
const splitted = arg.split(" ");
return { argumentName: splitted[0], dataType: splitted[1] };

let functArgs: FunctionArgument[] = [];
// regex by comma but not the comma within double quotes:
// e.g. Encounter "Encounter, Performed", "Encounter 2" "Encounter, Performed"
const regexByComma = /,(?=(?:[^"]*"[^"]*")*[^"]*$)/;
const resultByComma = args.split(regexByComma);

resultByComma.forEach((str) => {
//regex by space but not the space within double quotes, same example as above
const regexBySpace = /\w+|"(?:\\"|[^"])+"/g;
const resultBySpace = str.match(regexBySpace);

functArgs.push({
argumentName: resultBySpace[0],
dataType: resultBySpace[1],
});
});
return functArgs;
};

const getExpressionEditorValue = (logic: string): string => {
Expand Down

0 comments on commit 42b18ae

Please sign in to comment.