mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 11:42:36 +01:00
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:
parent
7b0c79c5ee
commit
e74bd45579
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user