Some minor optimizations inspired by #1814 - thx invandrofly :)

Fix  #1814
This commit is contained in:
Nikolaj Olsson 2016-06-29 19:22:06 +02:00
parent 8918e96039
commit ff8a832f1b
6 changed files with 21 additions and 20 deletions

View File

@ -56,7 +56,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
}
else if (!string.IsNullOrEmpty(nextText) && next != null &&
next.Text.Length > 0 &&
Utilities.UppercaseLetters.Contains(nextText[0]) &&
char.IsUpper(nextText[0]) &&
tempNoHtml.Length > 0 &&
!ExpectedString1.Contains(tempNoHtml[tempNoHtml.Length - 1]))
{
@ -103,7 +103,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
var st = new StripableText(next.Text);
if (st.StrippedText.Length > 0 && st.StrippedText != st.StrippedText.ToUpper() &&
Utilities.UppercaseLetters.Contains(st.StrippedText[0]))
char.IsUpper(st.StrippedText[0]))
{
if (callbacks.AllowFix(p, fixAction))
{
@ -134,7 +134,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i>-", 3, StringComparison.Ordinal);
if (indexOfNewLine < 0)
indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i> -", 3, StringComparison.Ordinal);
if (indexOfNewLine > 0 && Configuration.Settings.General.UppercaseLetters.Contains(char.ToUpper(p.Text[indexOfNewLine - 1])) && callbacks.AllowFix(p, fixAction))
if (indexOfNewLine > 0 && char.IsUpper(char.ToUpper(p.Text[indexOfNewLine - 1])) && callbacks.AllowFix(p, fixAction))
{
string oldText = p.Text;

View File

@ -330,10 +330,10 @@ namespace Nikse.SubtitleEdit.Core.Forms
if (arr0.Length > 0 && arr1.Length > 1)
{
// line continuation?
if (Utilities.LowercaseLetters.Contains(arr1[0])) // second line starts with lower case letter
if (char.IsLower(arr1[0])) // second line starts with lower case letter
{
char c = arr0[arr0.Length - 1];
if (Utilities.LowercaseLetters.Contains(c) || c == ',') // first line ends with comma or lower case letter
if (char.IsLower(c) || c == ',') // first line ends with comma or lower case letter
{
if (!arr1Stripable.Pre.Contains("..."))
{

View File

@ -257,7 +257,7 @@ namespace Nikse.SubtitleEdit.Core
if (s == ']' && idx > 1)
{ // I [Motor roaring] love you!
string temp = sb.ToString(0, idx - 1).Trim();
if (temp.Length > 0 && !Utilities.LowercaseLetters.Contains(temp[temp.Length - 1]))
if (temp.Length > 0 && !char.IsLower(temp[temp.Length - 1]))
lastWasBreak = true;
}
else

View File

@ -227,7 +227,7 @@ namespace Nikse.SubtitleEdit.Forms
if (merge && (p.Text.TrimEnd().EndsWith('!') || p.Text.TrimEnd().EndsWith('.')))
{
var st = new StripableText(p.Text);
if (st.StrippedText.Length > 0 && Utilities.UppercaseLetters.Contains(st.StrippedText[0].ToString(CultureInfo.InvariantCulture)))
if (st.StrippedText.Length > 0 && char.IsUpper(st.StrippedText[0]))
merge = false;
}

View File

@ -603,7 +603,7 @@ namespace Nikse.SubtitleEdit.Forms
suggestions = DoSuggest(_currentWord); // TODO: 0.9.6 fails on "Lt'S"
if (_languageName.StartsWith("fr_", StringComparison.Ordinal) && (_currentWord.StartsWith("I'", StringComparison.Ordinal) || _currentWord.StartsWith("I", StringComparison.Ordinal)))
{
if (_currentWord.Length > 3 && Utilities.LowercaseLetters.Contains(_currentWord[2]) && _currentSpellCheckWord.Index > 3)
if (_currentWord.Length > 3 && char.IsLower(_currentWord[2]) && _currentSpellCheckWord.Index > 3)
{
string ending = _currentParagraph.Text.Substring(0, _currentSpellCheckWord.Index - 1).Trim();
if (ending.Length > 1 && !".!?".Contains(ending[ending.Length - 1]))

View File

@ -449,22 +449,22 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
lastLine.EndsWith(".</font>", StringComparison.Ordinal) || lastLine.EndsWith("!</font>", StringComparison.Ordinal) || lastLine.EndsWith("?</font>", StringComparison.Ordinal);
if (text.StartsWith(tag.TrimStart(), StringComparison.Ordinal) && text.Length > 3)
{
if (endingBeforeThis || Utilities.UppercaseLetters.Contains(text[2]))
if (endingBeforeThis || char.IsUpper(text[2]))
{
text = @"L" + text.Substring(1);
}
else if (Utilities.LowercaseLetters.Contains(text[2]))
else if (char.IsLower(text[2]))
{
text = @"l" + text.Substring(1);
}
}
else if (text.StartsWith("<i>" + tag.TrimStart(), StringComparison.Ordinal) && text.Length > 6)
{
if (endingBeforeThis || Utilities.UppercaseLetters.Contains(text[5]))
if (endingBeforeThis || char.IsUpper(text[5]))
{
text = text.Remove(3, 1).Insert(3, "L");
}
else if (Utilities.LowercaseLetters.Contains(text[5]))
else if (char.IsLower(text[5]))
{
text = text.Remove(3, 1).Insert(3, "l");
}
@ -532,11 +532,11 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
endingBeforeThis = string.IsNullOrEmpty(lastLine) || lastLine.EndsWith('.') || lastLine.EndsWith('!') || lastLine.EndsWith('?') || lastLine.EndsWith(".</i>", StringComparison.Ordinal);
if (start < text.Length - 8)
{
if (endingBeforeThis || Utilities.UppercaseLetters.Contains(text[start + 5 + Environment.NewLine.Length]))
if (endingBeforeThis || char.IsUpper(text[start + 5 + Environment.NewLine.Length]))
{
text = text.Remove(start + Environment.NewLine.Length + 3, 1).Insert(start + Environment.NewLine.Length + 3, "L");
}
else if (Utilities.LowercaseLetters.Contains(text[start + 5 + Environment.NewLine.Length]))
else if (char.IsLower(text[start + 5 + Environment.NewLine.Length]))
{
text = text.Remove(start + Environment.NewLine.Length + 3, 1).Insert(start + Environment.NewLine.Length + 3, "l");
}
@ -783,24 +783,24 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
input = input.Remove(0, 1);
}
if (input.Length > 2 && input[0] == '-' && Utilities.UppercaseLetters.Contains(input[1]))
if (input.Length > 2 && input[0] == '-' && char.IsUpper(input[1]))
{
input = input.Insert(1, " ");
}
if (input.Length > 5 && input.StartsWith("<i>-", StringComparison.Ordinal) && Utilities.UppercaseLetters.Contains(input[4]))
if (input.Length > 5 && input.StartsWith("<i>-", StringComparison.Ordinal) && char.IsUpper(input[4]))
{
input = input.Insert(4, " ");
}
int idx = input.IndexOf(Environment.NewLine + "-", StringComparison.Ordinal);
if (idx > 0 && idx + Environment.NewLine.Length + 1 < input.Length && Utilities.UppercaseLetters.Contains(input[idx + Environment.NewLine.Length + 1]))
if (idx > 0 && idx + Environment.NewLine.Length + 1 < input.Length && char.IsUpper(input[idx + Environment.NewLine.Length + 1]))
{
input = input.Insert(idx + Environment.NewLine.Length + 1, " ");
}
idx = input.IndexOf(Environment.NewLine + "<i>-", StringComparison.Ordinal);
if (idx > 0 && Utilities.UppercaseLetters.Contains(input[idx + Environment.NewLine.Length + 4]))
if (idx > 0 && char.IsUpper(input[idx + Environment.NewLine.Length + 4]))
{
input = input.Insert(idx + Environment.NewLine.Length + 4, " ");
}
@ -1154,9 +1154,10 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
int uppercase = 0;
for (int i = 0; i < word.Length; i++)
{
if (Utilities.LowercaseLetters.Contains(word[i]))
var ch = word[i];
if (char.IsLower(ch))
lowercase++;
else if (Utilities.UppercaseLetters.Contains(word[i]))
else if (char.IsUpper(ch))
uppercase++;
}
if (uppercase > lowercase)