modifications to generic parser

This commit is contained in:
Justin Greywolf
2023-08-25 13:08:51 -07:00
parent 8e64995047
commit 3678ad4e9d
2 changed files with 5 additions and 21 deletions

View File

@@ -15,6 +15,7 @@ import {
setDiagramTitle,
getDiagramTitle,
} from '../../commonDb.js';
import { ClassMember } from './classTypes.js';
import type {
ClassRelation,
ClassNode,
@@ -22,7 +23,6 @@ import type {
ClassMap,
NamespaceMap,
NamespaceNode,
ClassMember,
} from './classTypes.js';
const MERMAID_DOM_ID_PREFIX = 'classId-';

View File

@@ -181,46 +181,31 @@ export const getMin = function (...values: number[]): number {
export const parseGenericTypes = function (input: string): string {
const inputSets = input.split(/(,)/);
const output = [];
let finalResult = '';
let skipNextSet = false;
for (let i = 0; i < inputSets.length; i++) {
const previousIndex = i - 1;
const nextIndex = i + 1;
let thisSet = inputSets[i];
// based on logic below - if we have already combined this set with the previous, we want to skip it
if (skipNextSet) {
continue;
}
// if the original input included a value such as "~K, V~"", these will be split into
// an array of ["~K",","," V~"].
// This means that on each call of processSet, there will only be 1 ~ present
// To account for this, if we encounter a ",", we are checking the previous and next sets in the array
// to see if they contain matching ~'s
// in which case we are assuming that they should be rejoined and sent to be processed
// we are also removing
if (thisSet === ',' && previousIndex > -1 && nextIndex <= inputSets.length) {
if (thisSet === ',' && i > 0 && i + 1 < inputSets.length) {
const previousSet = inputSets[i - 1];
const nextSet = inputSets[i + 1];
if (shouldCombineSets(previousSet, nextSet)) {
thisSet = previousSet + ',' + nextSet;
skipNextSet = true;
// remove previous set
i++; // Move the index forward to skip the next iteration since we're combining sets
output.pop();
}
} else {
skipNextSet = false;
}
output.push(processSet(thisSet));
}
finalResult = output.join('');
// one last scan to see if any sets were missed
finalResult = processSet(finalResult);
return finalResult;
return output.join('');
};
const shouldCombineSets = (previousSet: string, nextSet: string): boolean => {
@@ -234,7 +219,6 @@ const processSet = (input: string): string => {
const chars = [...input];
const tildeCount = chars.reduce((count, char) => (char === '~' ? count + 1 : count), 0);
// ignoring any
if (tildeCount <= 1) {
return input;
}