SubtitleEdit/libse/NoBreakAfterItem.cs

63 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core
{
public class NoBreakAfterItem : IComparable<NoBreakAfterItem>
{
public Regex Regex { get; }
public readonly string Text;
public NoBreakAfterItem(Regex regex, string text)
{
Regex = regex;
Text = text;
}
public NoBreakAfterItem(string text)
{
Text = text;
}
public bool IsMatch(string line)
{
// Make sure that both *line and *Text are not null.
if (string.IsNullOrEmpty(line) || string.IsNullOrEmpty(Text))
2019-01-19 14:40:37 +01:00
{
return false;
2019-01-19 14:40:37 +01:00
}
if (Regex != null)
2019-01-19 14:40:37 +01:00
{
return Regex.IsMatch(line);
2019-01-19 14:40:37 +01:00
}
return line.EndsWith(Text, StringComparison.Ordinal);
}
public override string ToString()
{
return Text;
}
public int CompareTo(NoBreakAfterItem obj)
{
if (obj == null)
2019-01-19 14:40:37 +01:00
{
return -1;
2019-01-19 14:40:37 +01:00
}
if (obj.Text == null && Text == null)
2019-01-19 14:40:37 +01:00
{
return 0;
2019-01-19 14:40:37 +01:00
}
else if (obj.Text == null)
2019-01-19 14:40:37 +01:00
{
return -1;
2019-01-19 14:40:37 +01:00
}
return string.Compare(Text, obj.Text, StringComparison.Ordinal);
}
}
2016-01-24 11:51:04 +01:00
}