[NoBreakAfterItem] - Use generic IComparable.

This commit is contained in:
Ivandro Ismael 2016-04-05 03:01:19 +01:00
parent ab8c8f6874
commit 4c511d0228

View File

@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core namespace Nikse.SubtitleEdit.Core
{ {
public class NoBreakAfterItem : IComparable public class NoBreakAfterItem : IComparable<NoBreakAfterItem>
{ {
public readonly Regex Regex; public readonly Regex Regex;
public readonly string Text; public readonly string Text;
@ -21,13 +21,12 @@ namespace Nikse.SubtitleEdit.Core
public bool IsMatch(string line) public bool IsMatch(string line)
{ {
// Make sure that both *line and *Text are not null.
if (string.IsNullOrEmpty(line) || string.IsNullOrEmpty(Text))
return false;
if (Regex != null) if (Regex != null)
return Regex.IsMatch(line); return Regex.IsMatch(line);
return line.EndsWith(Text, StringComparison.Ordinal);
if (!string.IsNullOrEmpty(Text) && line.EndsWith(Text, StringComparison.Ordinal))
return true;
return false;
} }
public override string ToString() public override string ToString()
@ -35,22 +34,15 @@ namespace Nikse.SubtitleEdit.Core
return Text; return Text;
} }
public int CompareTo(object obj) public int CompareTo(NoBreakAfterItem obj)
{ {
if (obj == null) if (obj == null)
return -1; return -1;
if (obj.Text == null && Text == null)
var o = obj as NoBreakAfterItem;
if (o == null)
return -1;
if (o.Text == null && this.Text == null)
return 0; return 0;
else if (obj.Text == null)
if (o.Text == null)
return -1; return -1;
return string.Compare(Text, obj.Text, StringComparison.Ordinal);
return string.Compare(Text, o.Text, StringComparison.Ordinal);
} }
} }
} }