forked from CoderLine/alphaTab
-
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.
Improve Beaming algorithm to handle collisions (CoderLine#491)
- Loading branch information
1 parent
968764a
commit 7ea8d9e
Showing
18 changed files
with
309 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,57 @@ | ||
using System.Text.RegularExpressions; | ||
using System.Collections.Concurrent; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace AlphaTab.Core.EcmaScript | ||
{ | ||
public class RegExp | ||
{ | ||
private static ConcurrentDictionary<(string pattern, string flags), RegExp> Cache = | ||
new ConcurrentDictionary<(string pattern, string flags), RegExp>(); | ||
|
||
private readonly Regex _regex; | ||
private readonly bool _global; | ||
|
||
public RegExp(string regex) | ||
public RegExp(string regex, string flags = "") | ||
{ | ||
_regex = new Regex(regex, RegexOptions.Compiled); | ||
if (!Cache.TryGetValue((regex, flags), out var cached)) | ||
{ | ||
var netFlags = RegexOptions.Compiled; | ||
foreach (var c in flags) | ||
{ | ||
switch (c) | ||
{ | ||
case 'i': | ||
netFlags |= RegexOptions.IgnoreCase; | ||
break; | ||
case 'g': | ||
_global = true; | ||
break; | ||
case 'm': | ||
netFlags |= RegexOptions.Multiline; | ||
break; | ||
} | ||
} | ||
|
||
_regex = new Regex(regex, netFlags); | ||
Cache[(regex, flags)] = this; | ||
} | ||
else | ||
{ | ||
_regex = cached._regex; | ||
_global = cached._global; | ||
} | ||
} | ||
|
||
public bool Exec(string s) | ||
{ | ||
return _regex.IsMatch(s); | ||
} | ||
|
||
public string Replace(string input, string replacement) | ||
{ | ||
return _global | ||
? _regex.Replace(input, replacement) | ||
: _regex.Replace(input, replacement, 1); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.