forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the approach from mermaid-js#4910 pr
- Loading branch information
1 parent
c364715
commit 32d82a6
Showing
3 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const STICKY_FLAG = 'y'; | ||
|
||
/** | ||
* Check to see if text matches any of the given RegExps. Return true as soon | ||
* as there is a match. Use the sticky flag on all RegExps. | ||
* | ||
* @param text - the string to try to match | ||
* @param startingOffset - offset to start at | ||
* @param regexps - a list of RegExps to check for matches | ||
* @internal | ||
* | ||
* @returns true if the text matches any of the RegExps (with the sticky flag set), | ||
* else returns false. | ||
*/ | ||
export function matchAnyRegexps(text: string, startingOffset: number, regexps: RegExp[]): boolean { | ||
const found = false; | ||
for (const regexp of regexps) { | ||
const currentRegexp = new RegExp(regexp, regexp.flags + STICKY_FLAG); | ||
currentRegexp.lastIndex = startingOffset; | ||
if (currentRegexp.exec(text) !== null) { | ||
return true; | ||
} | ||
} | ||
return found; | ||
} |