mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 04:33:04 +01:00
[Refact] - Check if char is letter using built-in method char.IsLetter().
This commit is contained in:
parent
a0b094f435
commit
aa11ca5340
@ -286,13 +286,9 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
int j = 1;
|
||||
while (j < newText.Length)
|
||||
{
|
||||
if (@"!?:;".Contains(newText[j]))
|
||||
if (@"!?:;".Contains(newText[j]) && char.IsLetter(newText[j - 1]))
|
||||
{
|
||||
if (Utilities.AllLetters.Contains(newText[j - 1]))
|
||||
{
|
||||
newText = newText.Insert(j, " ");
|
||||
j++;
|
||||
}
|
||||
newText = newText.Insert(j++, " ");
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
@ -205,10 +205,9 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
|
||||
string word = string.Empty;
|
||||
int i = index - 1;
|
||||
while (i >= 0 && Utilities.AllLetters.Contains(text[i]))
|
||||
while (i >= 0 && char.IsLetter(text[i]))
|
||||
{
|
||||
word = text[i] + word;
|
||||
i--;
|
||||
word = text[i--] + word;
|
||||
}
|
||||
|
||||
//Common Spanish abbreviations
|
||||
|
@ -228,7 +228,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
|
||||
if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith('.') &&
|
||||
prevText[prevText.Length - 3] == '.' &&
|
||||
Utilities.AllLetters.Contains(prevText[prevText.Length - 2]))
|
||||
char.IsLetter(prevText[prevText.Length - 2]))
|
||||
isPrevEndOfLine = false;
|
||||
return isPrevEndOfLine;
|
||||
}
|
||||
@ -407,7 +407,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
int newLineIdx = text.IndexOf(Environment.NewLine, StringComparison.Ordinal);
|
||||
bool addSecondLine = idx < newLineIdx;
|
||||
|
||||
if (addSecondLine && idx > 0 && Utilities.AllLetters.Contains(text[idx - 1]))
|
||||
if (addSecondLine && idx > 0 && char.IsLetter(text[idx - 1]))
|
||||
addSecondLine = false;
|
||||
if (addSecondLine)
|
||||
{
|
||||
|
@ -1882,17 +1882,15 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
string before = string.Empty;
|
||||
int k = idx - 1;
|
||||
while (k >= 0 && AllLettersAndNumbers.Contains(text[k]))
|
||||
while (k >= 0 && char.IsLetterOrDigit(text[k]))
|
||||
{
|
||||
before = text[k] + before;
|
||||
k--;
|
||||
before = text[k--] + before;
|
||||
}
|
||||
string after = string.Empty;
|
||||
k = idx + 2;
|
||||
while (k < text.Length && AllLetters.Contains(text[k]))
|
||||
while (k < text.Length && char.IsLetter(text[k]))
|
||||
{
|
||||
after = after + text[k];
|
||||
k++;
|
||||
after = after + text[k++];
|
||||
}
|
||||
if (after.Length > 0 && after.Equals(before, StringComparison.OrdinalIgnoreCase))
|
||||
text = text.Remove(idx + 1, 1);
|
||||
@ -1929,7 +1927,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
int idxp = text.IndexOf('"');
|
||||
|
||||
//"Foo " bar.
|
||||
if ((idxp >= 0 && idxp < idx) && AllLettersAndNumbers.Contains(text[idx - 1]) && !" \r\n".Contains(text[idxp + 1]))
|
||||
if ((idxp >= 0 && idxp < idx) && char.IsLetterOrDigit(text[idx - 1]) && !" \r\n".Contains(text[idxp + 1]))
|
||||
{
|
||||
text = text.Remove(idx, 1);
|
||||
}
|
||||
@ -1939,7 +1937,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
idxp = text.IndexOf('"');
|
||||
if (idxp >= 0 && idx > idxp)
|
||||
{
|
||||
if (text[idxp + 1] == ' ' && AllLettersAndNumbers.Contains(text[idxp + 2]))
|
||||
if (text[idxp + 1] == ' ' && char.IsLetterOrDigit(text[idxp + 2]))
|
||||
{
|
||||
text = text.Remove(idxp + 1, 1);
|
||||
idx--;
|
||||
|
@ -6494,12 +6494,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
else
|
||||
{
|
||||
unItalicText = unItalicText.Replace("</i>", string.Empty);
|
||||
if (line.EndsWith("</i>") && unItalicText.EndsWith('.'))
|
||||
if (line.EndsWith("</i>", StringComparison.Ordinal) && unItalicText.EndsWith('.'))
|
||||
{
|
||||
line = line.Remove(line.Length - 4, 4);
|
||||
if (line.EndsWith('-'))
|
||||
line = line.TrimEnd('-') + ".";
|
||||
if (Utilities.AllLetters.Contains(line.Substring(line.Length - 1)))
|
||||
if (char.IsLetter(line[line.Length - 1]))
|
||||
line += ".";
|
||||
line += "</i>";
|
||||
}
|
||||
|
@ -664,7 +664,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
|
||||
return true;
|
||||
}
|
||||
|
||||
if (line.Length > 5 && line[line.Length - 3] == '.' && Utilities.AllLetters.Contains(line[line.Length - 2]))
|
||||
if (line.Length > 5 && line[line.Length - 3] == '.' && char.IsLetter(line[line.Length - 2]))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user