mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Minor refactor
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1020 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
392fb7c680
commit
56dbcfd375
@ -115,7 +115,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
int j = start + colorTag.Length;
|
||||
if ("\"'".Contains(tag[j].ToString()))
|
||||
j++;
|
||||
while (j < tag.Length && ("#" + Utilities.GetLetters(false, true, true)).Contains(tag[j].ToString()))
|
||||
while (j < tag.Length && ("#" + Utilities.LowercaseLettersWithNumbers).Contains(tag[j].ToString()))
|
||||
{
|
||||
tempColor += tag[j].ToString();
|
||||
j++;
|
||||
|
@ -937,14 +937,14 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
string before = string.Empty;
|
||||
int k = idx - 1;
|
||||
while (k >= 0 && Utilities.GetLetters(true, true, true).Contains(p.Text[k].ToString()))
|
||||
while (k >= 0 && Utilities.AllLettersAndNumbers.Contains(p.Text[k].ToString()))
|
||||
{
|
||||
before = p.Text[k].ToString() + before;
|
||||
k--;
|
||||
}
|
||||
string after = string.Empty;
|
||||
k = idx + 2;
|
||||
while (k < p.Text.Length && Utilities.GetLetters(true, true, false).Contains(p.Text[k].ToString()))
|
||||
while (k < p.Text.Length && Utilities.AllLetters.Contains(p.Text[k].ToString()))
|
||||
{
|
||||
after = after + p.Text[k].ToString();
|
||||
k++;
|
||||
@ -1290,8 +1290,8 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
if (newText.Length > index + 4 && index > 1)
|
||||
{
|
||||
if (Utilities.GetLetters(true, true, true).Contains(newText[index + 3].ToString()) &&
|
||||
Utilities.GetLetters(true, true, true).Contains(newText[index -1].ToString()))
|
||||
if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3].ToString()) &&
|
||||
Utilities.AllLettersAndNumbers.Contains(newText[index - 1].ToString()))
|
||||
newText = newText.Insert(index + 3, " ");
|
||||
}
|
||||
index = newText.IndexOf("...", index +2);
|
||||
@ -1597,7 +1597,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
if (match.Index > 2 && st.StrippedText[match.Index - 1] == ' ')
|
||||
{
|
||||
if ((Utilities.GetLetters(true, true, true) + ",").Contains(st.StrippedText[match.Index - 2].ToString()))
|
||||
if ((Utilities.AllLettersAndNumbers + ",").Contains(st.StrippedText[match.Index - 2].ToString()))
|
||||
{
|
||||
string secondLetter = string.Empty;
|
||||
if (match.Length >= 2)
|
||||
@ -1614,7 +1614,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
else if (match.Index > Environment.NewLine.Length + 1 && Environment.NewLine.Contains(st.StrippedText[match.Index - 1].ToString()))
|
||||
{
|
||||
if ((Utilities.GetLetters(true, true, true) + ",").Contains(st.StrippedText[match.Index - (Environment.NewLine.Length + 1)].ToString()))
|
||||
if ((Utilities.AllLettersAndNumbers + ",").Contains(st.StrippedText[match.Index - (Environment.NewLine.Length + 1)].ToString()))
|
||||
{
|
||||
string next = string.Empty;
|
||||
if (match.Length >= 2)
|
||||
@ -1724,7 +1724,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(nextText) && next != null &&
|
||||
next.Text.Length > 0 &&
|
||||
Utilities.GetLetters(true, false, false).Contains(nextText[0].ToString()) &&
|
||||
Utilities.UppercaseLetters.Contains(nextText[0].ToString()) &&
|
||||
tempNoHtml.Length > 0 &&
|
||||
(!"\",.!?:;>-])♪♫".Contains(tempNoHtml[tempNoHtml.Length - 1].ToString())))
|
||||
{
|
||||
@ -1763,13 +1763,13 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (next != null && !string.IsNullOrEmpty(p.Text) && Utilities.GetLetters(true, true, true).Contains(p.Text[p.Text.Length-1].ToString()))
|
||||
else if (next != null && !string.IsNullOrEmpty(p.Text) && Utilities.AllLettersAndNumbers.Contains(p.Text[p.Text.Length-1].ToString()))
|
||||
{
|
||||
if (p.Text != p.Text.ToUpper())
|
||||
{
|
||||
StripableText st = new StripableText(next.Text);
|
||||
if (st.StrippedText.Length > 0 && st.StrippedText != st.StrippedText.ToUpper() &&
|
||||
Utilities.GetLetters(true, false, false).Contains(st.StrippedText[0].ToString()))
|
||||
Utilities.UppercaseLetters.Contains(st.StrippedText[0].ToString()))
|
||||
{
|
||||
if (AllowFix(p, fixAction))
|
||||
{
|
||||
@ -2049,7 +2049,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith(".") &&
|
||||
prevText[prevText.Length - 3] == '.' &&
|
||||
Utilities.GetLetters(true, true, false).Contains(prevText[prevText.Length - 2].ToString()))
|
||||
Utilities.AllLetters.Contains(prevText[prevText.Length - 2].ToString()))
|
||||
isPrevEndOfLine = false;
|
||||
return isPrevEndOfLine;
|
||||
}
|
||||
@ -2114,12 +2114,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
if (text[index] != '.' && text[index] != '!' && text[index] != '?')
|
||||
return false;
|
||||
|
||||
if (index - 3 > 0 && Utilities.GetLetters(true, true, true).Contains(text[index - 1].ToString()) && text[index - 2] == '.') // e.g: O.R.
|
||||
if (index - 3 > 0 && Utilities.AllLettersAndNumbers.Contains(text[index - 1].ToString()) && text[index - 2] == '.') // e.g: O.R.
|
||||
return true;
|
||||
|
||||
string word = string.Empty;
|
||||
int i = index - 1;
|
||||
while (i >= 0 && Utilities.GetLetters(true, true, false).Contains(text[i].ToString()))
|
||||
while (i >= 0 && Utilities.AllLetters.Contains(text[i].ToString()))
|
||||
{
|
||||
word = text[i].ToString() + word;
|
||||
i--;
|
||||
@ -2204,10 +2204,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
string part0 = Utilities.RemoveHtmlTags(parts[0]).Trim();
|
||||
string part1 = Utilities.RemoveHtmlTags(parts[1]).Trim();
|
||||
if (part0.Length > 1 && "!?.".Contains(part0.Substring(part0.Length - 1, 1)) &&
|
||||
part1.Length > 1 && ("'" + Utilities.GetLetters(true, false, false)).Contains(part1.Substring(0, 1)))
|
||||
part1.Length > 1 && ("'" + Utilities.UppercaseLetters).Contains(part1.Substring(0, 1)))
|
||||
{
|
||||
text = text.Replace(" - ", Environment.NewLine + "- ");
|
||||
if (Utilities.GetLetters(true, true, true).Contains(part0.Substring(0, 1)))
|
||||
if (Utilities.AllLettersAndNumbers.Contains(part0.Substring(0, 1)))
|
||||
{
|
||||
if (text.StartsWith("<i>"))
|
||||
text = "<i>- " + text;
|
||||
@ -3507,7 +3507,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
string word = string.Empty;
|
||||
int i = index-1;
|
||||
while (i >= 0 && Utilities.GetLetters(true, true, false).Contains(text[i].ToString()))
|
||||
while (i >= 0 && Utilities.AllLetters.Contains(text[i].ToString()))
|
||||
{
|
||||
word = text[i].ToString() + word;
|
||||
i--;
|
||||
|
@ -113,7 +113,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
if (merge && (p.Text.TrimEnd().EndsWith("!") || p.Text.TrimEnd().EndsWith(".") || p.Text.TrimEnd().EndsWith("!")))
|
||||
{
|
||||
StripableText st = new StripableText(p.Text);
|
||||
if (st.StrippedText.Length > 0 && Utilities.GetLetters(true, false, false).Contains(st.StrippedText[0].ToString()))
|
||||
if (st.StrippedText.Length > 0 && Utilities.UppercaseLetters.Contains(st.StrippedText[0].ToString()))
|
||||
merge = false;
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
private bool ContainsLetters(string line)
|
||||
{
|
||||
string letterList = Utilities.GetLetters(true, true, false);
|
||||
string letterList = Utilities.AllLetters;
|
||||
foreach (char ch in line.ToCharArray())
|
||||
{
|
||||
if (letterList.Contains(ch.ToString()))
|
||||
|
@ -236,7 +236,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
return true;
|
||||
bool isLineContinuation = s.EndsWith(",") || s.EndsWith("-") || s.EndsWith("...") || Utilities.GetLetters(true, true, true).Contains(s.Substring(s.Length - 1));
|
||||
bool isLineContinuation = s.EndsWith(",") || s.EndsWith("-") || s.EndsWith("...") || Utilities.AllLettersAndNumbers.Contains(s.Substring(s.Length - 1));
|
||||
|
||||
if (!checkBoxOnlyContinuationLines.Checked)
|
||||
return true;
|
||||
|
@ -422,8 +422,8 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
string arr1 = new StripableText(arr[1]).StrippedText;
|
||||
|
||||
//line continuation?
|
||||
if (arr0.Length > 0 && arr1.Length > 1 && (Utilities.GetLetters(false, true, false) + ",").Contains(arr0.Substring(arr0.Length - 1)) &&
|
||||
Utilities.GetLetters(false, true, false).Contains(arr1.Substring(0, 1)))
|
||||
if (arr0.Length > 0 && arr1.Length > 1 && (Utilities.LowercaseLetters + ",").Contains(arr0.Substring(arr0.Length - 1)) &&
|
||||
Utilities.LowercaseLetters.Contains(arr1.Substring(0, 1)))
|
||||
{
|
||||
if (new StripableText(arr[1]).Pre.Contains("...") == false)
|
||||
insertDash = false;
|
||||
|
@ -320,7 +320,7 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
else
|
||||
{
|
||||
bool doFixWord = true;
|
||||
if (word.Length == 1 && sb.ToString().EndsWith("-") && sb.Length > 1)
|
||||
if (word.Length == 1 && sb.Length > 1 && sb.ToString().EndsWith("-"))
|
||||
doFixWord = false;
|
||||
if (doFixWord)
|
||||
fixedWord = FixCommonWordErrors(word.ToString(), lastWord);
|
||||
@ -342,7 +342,7 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
{
|
||||
string fixedWord;
|
||||
bool doFixWord = true;
|
||||
if (word.Length == 1 && sb.ToString().EndsWith("-") && sb.Length > 1)
|
||||
if (word.Length == 1 && sb.Length > 1 && sb.ToString().EndsWith("-"))
|
||||
doFixWord = false;
|
||||
if (doFixWord)
|
||||
fixedWord = FixCommonWordErrors(word.ToString(), lastWord);
|
||||
@ -474,28 +474,28 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
pre += "<i>";
|
||||
word = word.Remove(0, 3);
|
||||
}
|
||||
while (word.StartsWith(Environment.NewLine) && word.Length > 2)
|
||||
while (word.Length > 2 && word.StartsWith(Environment.NewLine))
|
||||
{
|
||||
pre += Environment.NewLine;
|
||||
word = word.Substring(2);
|
||||
}
|
||||
|
||||
while (word.StartsWith("-") && word.Length > 1)
|
||||
while (word.Length > 1 && word.StartsWith("-"))
|
||||
{
|
||||
pre += "-";
|
||||
word = word.Substring(1);
|
||||
}
|
||||
while (word.StartsWith(".") && word.Length > 1)
|
||||
while (word.Length > 1 && word.StartsWith("."))
|
||||
{
|
||||
pre += ".";
|
||||
word = word.Substring(1);
|
||||
}
|
||||
while (word.StartsWith("\"") && word.Length > 1)
|
||||
while (word.Length > 1 && word.StartsWith("\""))
|
||||
{
|
||||
pre += "\"";
|
||||
word = word.Substring(1);
|
||||
}
|
||||
if (word.StartsWith("(") && word.Length > 1)
|
||||
if (word.Length > 1 && word.StartsWith("("))
|
||||
{
|
||||
pre += "(";
|
||||
word = word.Substring(1);
|
||||
@ -505,17 +505,17 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
pre += "<i>";
|
||||
word = word.Remove(0, 3);
|
||||
}
|
||||
while (word.EndsWith(Environment.NewLine) && word.Length > 2)
|
||||
while (word.Length > 2 && word.EndsWith(Environment.NewLine))
|
||||
{
|
||||
post += Environment.NewLine;
|
||||
word = word.Substring(0, word.Length - 2);
|
||||
}
|
||||
while (word.EndsWith("\"") && word.Length > 1)
|
||||
while (word.Length > 1 && word.EndsWith("\""))
|
||||
{
|
||||
post = post + "\"";
|
||||
word = word.Substring(0, word.Length - 1);
|
||||
}
|
||||
while (word.EndsWith(".") && word.Length > 1)
|
||||
while (word.Length > 1 && word.EndsWith("."))
|
||||
{
|
||||
post = post + ".";
|
||||
word = word.Substring(0, word.Length - 1);
|
||||
@ -866,25 +866,23 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
{
|
||||
string l = lines[i];
|
||||
|
||||
if (i > 0)
|
||||
lastLine = lines[i - 1];
|
||||
lastLine = Utilities.RemoveHtmlTags(lastLine);
|
||||
if (i > 0)
|
||||
lastLine = lines[i - 1];
|
||||
lastLine = Utilities.RemoveHtmlTags(lastLine);
|
||||
|
||||
if (string.IsNullOrEmpty(lastLine) ||
|
||||
lastLine.EndsWith(".") ||
|
||||
lastLine.EndsWith("!") ||
|
||||
lastLine.EndsWith("?"))
|
||||
if (string.IsNullOrEmpty(lastLine) ||
|
||||
lastLine.EndsWith(".") ||
|
||||
lastLine.EndsWith("!") ||
|
||||
lastLine.EndsWith("?"))
|
||||
{
|
||||
StripableText st = new StripableText(l);
|
||||
if (st.StrippedText.StartsWith("i") && !st.Pre.EndsWith("[") && !st.Pre.EndsWith("("))
|
||||
{
|
||||
StripableText st = new StripableText(l);
|
||||
if (st.StrippedText.StartsWith("i") && !st.Pre.EndsWith("[") && !st.Pre.EndsWith("("))
|
||||
{
|
||||
if (string.IsNullOrEmpty(lastLine) || (!lastLine.EndsWith("...") && !EndsWithAbbreviation(lastLine, _abbreviationList)))
|
||||
{
|
||||
l = st.Pre + "I" + st.StrippedText.Remove(0, 1) + st.Post;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(lastLine) || (!lastLine.EndsWith("...") && !EndsWithAbbreviation(lastLine, _abbreviationList)))
|
||||
l = st.Pre + "I" + st.StrippedText.Remove(0, 1) + st.Post;
|
||||
}
|
||||
sb.AppendLine(l);
|
||||
}
|
||||
sb.AppendLine(l);
|
||||
}
|
||||
return sb.ToString().TrimEnd('\r').TrimEnd('\n').TrimEnd('\r').TrimEnd('\n');
|
||||
}
|
||||
@ -901,7 +899,7 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
return true;
|
||||
}
|
||||
|
||||
if (line.Length > 5 && line[line.Length - 3] == '.' && Utilities.GetLetters(true, true, false).Contains(line[line.Length - 2].ToString()))
|
||||
if (line.Length > 5 && line[line.Length - 3] == '.' && Utilities.AllLetters.Contains(line[line.Length - 2].ToString()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -985,24 +983,24 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
if (input.StartsWith("-...") && lastLine != null && lastLine.EndsWith("...") && !(input.Contains(Environment.NewLine + "-")))
|
||||
input = input.Remove(0, 1);
|
||||
|
||||
if (input.Length > 2 && input[0] == '-' && Utilities.GetLetters(true, false, false).Contains(input[1].ToString()))
|
||||
if (input.Length > 2 && input[0] == '-' && Utilities.UppercaseLetters.Contains(input[1].ToString()))
|
||||
{
|
||||
input = input.Insert(1, " ");
|
||||
}
|
||||
|
||||
if (input.Length > 5 && input.StartsWith("<i>-") && Utilities.GetLetters(true, false, false).Contains(input[4].ToString()))
|
||||
if (input.Length > 5 && input.StartsWith("<i>-") && Utilities.UppercaseLetters.Contains(input[4].ToString()))
|
||||
{
|
||||
input = input.Insert(4, " ");
|
||||
}
|
||||
|
||||
int idx = input.IndexOf(Environment.NewLine + "-");
|
||||
if (idx > 0 && idx + Environment.NewLine.Length + 1 < input.Length && Utilities.GetLetters(true, false, false).Contains(input[idx + Environment.NewLine.Length + 1].ToString()))
|
||||
if (idx > 0 && idx + Environment.NewLine.Length + 1 < input.Length && Utilities.UppercaseLetters.Contains(input[idx + Environment.NewLine.Length + 1].ToString()))
|
||||
{
|
||||
input = input.Insert(idx + Environment.NewLine.Length + 1, " ");
|
||||
}
|
||||
|
||||
idx = input.IndexOf(Environment.NewLine + "<i>-");
|
||||
if (idx > 0 && Utilities.GetLetters(true, false, false).Contains(input[idx + Environment.NewLine.Length + 4].ToString()))
|
||||
if (idx > 0 && Utilities.UppercaseLetters.Contains(input[idx + Environment.NewLine.Length + 4].ToString()))
|
||||
{
|
||||
input = input.Insert(idx + Environment.NewLine.Length + 4, " ");
|
||||
}
|
||||
@ -1380,15 +1378,13 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
||||
|
||||
private string GetWordWithDominatedCasing(string word)
|
||||
{
|
||||
string uppercaseLetters = Utilities.GetLetters(true, false, false);
|
||||
string lowercaseLetters = Utilities.GetLetters(false, true, false);
|
||||
int lowercase = 0;
|
||||
int uppercase = 0;
|
||||
for (int i = 0; i < word.Length; i++)
|
||||
{
|
||||
if (lowercaseLetters.Contains(word.Substring(i, 1)))
|
||||
if (Utilities.LowercaseLetters.Contains(word.Substring(i, 1)))
|
||||
lowercase++;
|
||||
else if (uppercaseLetters.Contains(word.Substring(i, 1)))
|
||||
else if (Utilities.UppercaseLetters.Contains(word.Substring(i, 1)))
|
||||
uppercase++;
|
||||
}
|
||||
if (uppercase > lowercase)
|
||||
|
@ -31,7 +31,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
OriginalText = text;
|
||||
|
||||
Pre = string.Empty;
|
||||
if (text.Length > 0 && !Utilities.GetLetters(true, true, true).Contains(text[0].ToString()))
|
||||
if (text.Length > 0 && !Utilities.AllLettersAndNumbers.Contains(text[0].ToString()))
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
@ -52,7 +52,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
}
|
||||
|
||||
Post = string.Empty;
|
||||
if (text.Length > 0 && !Utilities.GetLetters(true, true, true).Contains(text[text.Length - 1].ToString()))
|
||||
if (text.Length > 0 && !Utilities.AllLettersAndNumbers.Contains(text[text.Length - 1].ToString()))
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
@ -245,7 +245,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
if (s == "]" && sb.ToString().IndexOf("[") > 1)
|
||||
{ // I [Motor roaring] love you!
|
||||
string temp = sb.ToString().Substring(0, sb.ToString().IndexOf("[") - 1).Trim();
|
||||
if (temp.Length > 0 && !Utilities.GetLetters(false, true, false).Contains(temp[temp.Length - 1].ToString()))
|
||||
if (temp.Length > 0 && !Utilities.LowercaseLetters.Contains(temp[temp.Length - 1].ToString()))
|
||||
lastWasBreak = true;
|
||||
}
|
||||
else
|
||||
|
@ -157,7 +157,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
var className = new StringBuilder();
|
||||
int startClass = textToLower.IndexOf(" class=");
|
||||
int indexClass = startClass + 7;
|
||||
while (indexClass < textToLower.Length && Utilities.GetLetters(false, true, true).Contains(textToLower[indexClass].ToString()))
|
||||
while (indexClass < textToLower.Length && Utilities.LowercaseLettersWithNumbers.Contains(textToLower[indexClass].ToString()))
|
||||
{
|
||||
className.Append(text[indexClass].ToString());
|
||||
indexClass++;
|
||||
|
@ -1554,20 +1554,26 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
return userWordListXmlFileName;
|
||||
}
|
||||
|
||||
public static string GetLetters(bool uppercase, bool lowercase, bool numbers)
|
||||
public static string UppercaseLetters = GetLetters(true, false, false);
|
||||
public static string LowercaseLetters = GetLetters(false, true, false);
|
||||
public static string LowercaseLettersWithNumbers = GetLetters(false, true, false);
|
||||
public static string AllLetters = GetLetters(true, true, false);
|
||||
public static string AllLettersAndNumbers = GetLetters(true, true, false);
|
||||
|
||||
private static string GetLetters(bool uppercase, bool lowercase, bool numbers)
|
||||
{
|
||||
string s = string.Empty;
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (uppercase)
|
||||
s += Configuration.Settings.General.UppercaseLetters;
|
||||
sb.Append(Configuration.Settings.General.UppercaseLetters);
|
||||
|
||||
if (lowercase)
|
||||
s += Configuration.Settings.General.UppercaseLetters.ToLower();
|
||||
sb.Append(Configuration.Settings.General.UppercaseLetters.ToLower());
|
||||
|
||||
if (numbers)
|
||||
s += "0123456789";
|
||||
sb.Append("0123456789");
|
||||
|
||||
return s;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
internal static Color GetColorFromUserName(string userName)
|
||||
|
Loading…
Reference in New Issue
Block a user