Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/strippable #9165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/libse/Common/StrippableText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Nikse.SubtitleEdit.Core.Common
{
public class StrippableText
public struct StrippableText
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should bring huge improvement

{
private const string PrefixChars = " >-\"„”“['‘`´¶(♪¿¡.…—";
private const string SuffixChars = " -\"”“]'`´¶)♪.!?:…—؛،؟";

public string Pre { get; set; }
public string Post { get; set; }
public string StrippedText { get; set; }
Expand All @@ -14,7 +17,7 @@ public class StrippableText
public string MergedString => Pre + StrippedText + Post;

public StrippableText(string text)
: this(text, " >-\"„”“['‘`´¶(♪¿¡.…—", " -\"”“]'`´¶)♪.!?:…—؛،؟")
: this(text, PrefixChars, SuffixChars)
{
}

Expand Down Expand Up @@ -58,8 +61,7 @@ public StrippableText(string input, string stripStartCharacters, string stripEnd
Pre += text.Substring(0, endIndex);
text = text.Remove(0, endIndex);
}
}
while (text.Length < beginLength);
} while (text.Length < beginLength);
}

Post = string.Empty;
Expand Down Expand Up @@ -94,8 +96,7 @@ public StrippableText(string input, string stripStartCharacters, string stripEnd
text = text.Substring(0, text.Length - 7);
}
}
}
while (text.Length < beginLength);
} while (text.Length < beginLength);
}

StrippedText = text;
Expand Down Expand Up @@ -151,6 +152,7 @@ private void ReplaceNames1Remove(List<string> nameList, List<string> replaceIds,
lower = StrippedText.ToLowerInvariant();
}
}

if (start + 3 > lower.Length)
{
start = lower.Length + 1;
Expand Down Expand Up @@ -178,6 +180,7 @@ private void ReplaceNames2Fix(List<string> replaceIds, List<string> replaceNames
}

private static readonly char[] ExpectedCharsArray = { '.', '!', '?', ':', ';', ')', ']', '}', '(', '[', '{' };

public void FixCasing(List<string> nameList, bool changeNameCases, bool makeUppercaseAfterBreak, bool checkLastLine, string lastLine, double millisecondsFromLast = 0)
{
var replaceIds = new List<string>();
Expand Down Expand Up @@ -324,6 +327,7 @@ public void FixCasing(List<string> nameList, bool changeNameCases, bool makeUppe
}
}
}

StrippedText = sb.ToString();
}

Expand Down Expand Up @@ -389,6 +393,7 @@ private bool ShouldStartWithUpperCase(string lastLine, double millisecondsgaps)
lastChar = tempPreLine[tempPreLine.Length - 1];
}
}

if (lastChar == '.' || lastChar == '!' || lastChar == '?' || lastChar == ']' || lastChar == ')' || lastChar == ':' || lastChar == '_')
{
return true;
Expand All @@ -404,4 +409,4 @@ private bool ShouldStartWithUpperCase(string lastLine, double millisecondsgaps)
return false;
}
}
}
}