[regexutils] - minor updates

This commit is contained in:
Ivandro Ismael 2017-12-12 01:05:56 +00:00
parent 497d026b3e
commit fb86e865c9
3 changed files with 18 additions and 16 deletions

View File

@ -203,5 +203,17 @@ namespace Nikse.SubtitleEdit.Core
return new Regex(@"[\b ,\.\?\!]" + s + @"[\b !\.,\r\n\?]", RegexOptions.Compiled);
}
public static string GetRegExGroup(string pattern)
{
var start = pattern.IndexOf("(?<", StringComparison.Ordinal);
if (start < 0)
return null;
start += 3;
var end = pattern.IndexOf('>', start);
if (end <= start)
return null;
return pattern.Substring(start, end - start);
}
}
}

View File

@ -1045,18 +1045,6 @@ namespace Nikse.SubtitleEdit.Core
return (int)(number % 8);
}
public static string GetRegExGroup(string regEx)
{
var start = regEx.IndexOf("(?<", StringComparison.Ordinal);
if (start < 0)
return null;
start += 3;
var end = regEx.IndexOf('>', start);
if (end <= start)
return null;
return regEx.Substring(start, end - start);
}
public static string LowercaseVowels
{
get

View File

@ -78,7 +78,7 @@ namespace Nikse.SubtitleEdit.Logic
if (FindReplaceType.FindType == FindType.CaseSensitive || FindReplaceType.FindType == FindType.Normal)
{
var comparison = FindReplaceType.FindType == FindType.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
var comparison = GetComparison();
var idx = text.IndexOf(_findText, startIndex, comparison);
while (idx >= 0)
{
@ -101,7 +101,7 @@ namespace Nikse.SubtitleEdit.Logic
var match = _regEx.Match(text, startIndex);
if (match.Success)
{
string groupName = Utilities.GetRegExGroup(_findText);
string groupName = RegexUtils.GetRegExGroup(_findText);
if (groupName != null && match.Groups[groupName] != null && match.Groups[groupName].Success)
{
_findTextLenght = match.Groups[groupName].Length;
@ -221,7 +221,7 @@ namespace Nikse.SubtitleEdit.Logic
Match match = _regEx.Match(text, startIndex);
if (match.Success)
{
string groupName = Utilities.GetRegExGroup(_findText);
string groupName = RegexUtils.GetRegExGroup(_findText);
if (groupName != null && match.Groups[groupName] != null && match.Groups[groupName].Success)
{
_findTextLenght = match.Groups[groupName].Length;
@ -260,7 +260,7 @@ namespace Nikse.SubtitleEdit.Logic
}
_regEx = new Regex(_findText);
}
StringComparison comparison = FindReplaceType.FindType == FindType.Normal ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
var comparison = GetComparison();
foreach (var p in subtitle.Paragraphs)
{
if (FindReplaceType.FindType != FindType.RegEx)
@ -301,5 +301,7 @@ namespace Nikse.SubtitleEdit.Logic
return count;
}
private StringComparison GetComparison() => FindReplaceType.FindType == FindType.Normal ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
}
}