Refactor casing correction for contractions

Simplified the code by extracting repetitive checks for contractions into a dedicated method `IsSubjectVerb`. This improves readability and maintainability by reducing redundancy in the conditional statements.

Signed-off-by: Ivandro Jao <Ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-07-25 22:55:44 +01:00
parent 7b0c79c5ee
commit e74bd45579

View File

@ -139,19 +139,7 @@ namespace Nikse.SubtitleEdit.Core.Common
{
text = text.Remove(indexOfI - 2, 3).Insert(indexOfI - 2, "I-I");
}
else if (text.Substring(indexOfI).StartsWith("i'll ", StringComparison.Ordinal))
{
text = text.Remove(indexOfI, 1).Insert(indexOfI, "I");
}
else if (text.Substring(indexOfI).StartsWith("i've ", StringComparison.Ordinal))
{
text = text.Remove(indexOfI, 1).Insert(indexOfI, "I");
}
else if (text.Substring(indexOfI).StartsWith("i'm ", StringComparison.Ordinal))
{
text = text.Remove(indexOfI, 1).Insert(indexOfI, "I");
}
else if (text.Substring(indexOfI).StartsWith("i'd ", StringComparison.Ordinal))
else if (IsSubjectVerb(text.Substring(indexOfI)))
{
text = text.Remove(indexOfI, 1).Insert(indexOfI, "I");
}
@ -159,6 +147,14 @@ namespace Nikse.SubtitleEdit.Core.Common
return text;
}
private static bool IsSubjectVerb(string input)
{
return input.StartsWith("i'll ", StringComparison.Ordinal) ||
input.StartsWith("i've ", StringComparison.Ordinal) ||
input.StartsWith("i'm ", StringComparison.Ordinal) ||
input.StartsWith("i'd ", StringComparison.Ordinal);
}
private string FixCasingAfterTitles(string input)
{
var text = input;