[Refact] - Check if char is letter using built-in method char.IsLetter().

This commit is contained in:
Ivandro Ismael 2016-07-11 19:33:39 +01:00
parent a0b094f435
commit aa11ca5340
No known key found for this signature in database
GPG Key ID: A8832757DEFB7EDC
6 changed files with 15 additions and 22 deletions

View File

@ -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++;
}

View File

@ -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

View File

@ -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)
{

View File

@ -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--;

View File

@ -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>";
}

View File

@ -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;