mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
More code quality improvements
This commit is contained in:
parent
e8495f7f8b
commit
b4aad6385b
@ -13,10 +13,10 @@ namespace Nikse.SubtitleEdit.Core
|
||||
private static readonly string SingleQuotes = "'‘’‘";
|
||||
private static readonly string DoubleQuotes = "''‘‘’’‚‚‘‘";
|
||||
|
||||
public static List<string> Prefixes = new List<string> { "...", "..", "-", "‐", "–", "—", "…" };
|
||||
public static List<string> Suffixes = new List<string> { "...", "..", "-", "‐", "–", "—", "…" };
|
||||
public static readonly List<string> Prefixes = new List<string> { "...", "..", "-", "‐", "–", "—", "…" };
|
||||
public static readonly List<string> Suffixes = new List<string> { "...", "..", "-", "‐", "–", "—", "…" };
|
||||
|
||||
public static string SanitizeString(string input, bool removeDashes = true, bool removeHtml = true)
|
||||
public static string SanitizeString(string input, bool removeDashes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
@ -24,10 +24,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
}
|
||||
|
||||
string checkString = input;
|
||||
if (removeHtml)
|
||||
{
|
||||
checkString = Regex.Replace(checkString, "<.*?>", string.Empty);
|
||||
}
|
||||
checkString = Regex.Replace(checkString, "<.*?>", string.Empty);
|
||||
checkString = Regex.Replace(checkString, "\\(.*?\\)", string.Empty);
|
||||
checkString = Regex.Replace(checkString, "\\[.*?\\]", string.Empty);
|
||||
checkString = Regex.Replace(checkString, "\\{.*?\\}", string.Empty);
|
||||
@ -96,7 +93,12 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return checkString;
|
||||
}
|
||||
|
||||
public static string ExtractParagraphOnly(string input, bool removeDashes = true)
|
||||
public static string SanitizeString(string input)
|
||||
{
|
||||
return SanitizeString(input, true);
|
||||
}
|
||||
|
||||
public static string ExtractParagraphOnly(string input, bool removeDashes)
|
||||
{
|
||||
string checkString = input;
|
||||
checkString = Regex.Replace(checkString, "\\{.*?\\}", string.Empty);
|
||||
@ -111,6 +113,11 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return checkString;
|
||||
}
|
||||
|
||||
public static string ExtractParagraphOnly(string input)
|
||||
{
|
||||
return ExtractParagraphOnly(input, true);
|
||||
}
|
||||
|
||||
public static string ReplaceFirstOccurrence(string source, string find, string replace)
|
||||
{
|
||||
int place = source.IndexOf(find, StringComparison.Ordinal);
|
||||
@ -137,7 +144,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool ShouldAddSuffix(string input, ContinuationProfile profile, bool sanitize = true)
|
||||
public static bool ShouldAddSuffix(string input, ContinuationProfile profile, bool sanitize)
|
||||
{
|
||||
string text = sanitize ? SanitizeString(input) : input;
|
||||
|
||||
@ -149,6 +156,11 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ShouldAddSuffix(string input, ContinuationProfile profile)
|
||||
{
|
||||
return ShouldAddSuffix(input, profile, true);
|
||||
}
|
||||
|
||||
public static string AddSuffixIfNeeded(string originalText, ContinuationProfile profile, bool gap)
|
||||
{
|
||||
// Get last word
|
||||
@ -223,7 +235,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return ReplaceFirstOccurrence(originalText, firstWord, newFirstWord);
|
||||
}
|
||||
|
||||
public static string RemoveSuffix(string originalText, ContinuationProfile profile, bool addComma = false)
|
||||
public static string RemoveSuffix(string originalText, ContinuationProfile profile, bool addComma)
|
||||
{
|
||||
// Get last word
|
||||
string text = SanitizeString(originalText);
|
||||
@ -249,6 +261,11 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return ReplaceLastOccurrence(originalText, lastWord, newLastWord);
|
||||
}
|
||||
|
||||
public static string RemoveSuffix(string originalText, ContinuationProfile profile)
|
||||
{
|
||||
return RemoveSuffix(originalText, profile, false);
|
||||
}
|
||||
|
||||
public static string RemovePrefix(string originalText, ContinuationProfile profile)
|
||||
{
|
||||
// Get first word of the next paragraph
|
||||
|
@ -13,7 +13,11 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddFixToListView(Paragraph p, string action, string before, string after, bool isChecked = true)
|
||||
public void AddFixToListView(Paragraph p, string action, string before, string after)
|
||||
{
|
||||
}
|
||||
|
||||
public void AddFixToListView(Paragraph p, string action, string before, string after, bool isChecked)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
callbacks.UpdateFixStatus(fixCount, language.FixUnnecessaryLeadingDots, language.XFixContinuationStyle);
|
||||
}
|
||||
|
||||
private bool IsPreviewStep(IFixCallbacks callbacks)
|
||||
private static bool IsPreviewStep(IFixCallbacks callbacks)
|
||||
{
|
||||
return callbacks.AllowFix(new Paragraph { Number = -1 }, string.Empty);
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ namespace Nikse.SubtitleEdit.Core.Interfaces
|
||||
public interface IFixCallbacks : IDoSpell
|
||||
{
|
||||
bool AllowFix(Paragraph p, string action);
|
||||
void AddFixToListView(Paragraph p, string action, string before, string after, bool isChecked = true);
|
||||
void AddFixToListView(Paragraph p, string action, string before, string after);
|
||||
void AddFixToListView(Paragraph p, string action, string before, string after, bool isChecked);
|
||||
void LogStatus(string sender, string message);
|
||||
void LogStatus(string sender, string message, bool isImportant);
|
||||
void UpdateFixStatus(int fixes, string message, string xMessage);
|
||||
|
@ -525,7 +525,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
listView1.Items.Add(item);
|
||||
}
|
||||
|
||||
public void AddFixToListView(Paragraph p, string action, string before, string after, bool isChecked = true)
|
||||
public void AddFixToListView(Paragraph p, string action, string before, string after)
|
||||
{
|
||||
AddFixToListView(p, action, before, after, true);
|
||||
}
|
||||
|
||||
public void AddFixToListView(Paragraph p, string action, string before, string after, bool isChecked)
|
||||
{
|
||||
if (_onlyListFixes)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user