public void StripableTextItalic()
 {
     var st = new StripableText("<i>Hi!</i>");
     Assert.AreEqual(st.Pre, "<i>");
     Assert.AreEqual(st.Post, "!</i>");
     Assert.AreEqual(st.StrippedText, "Hi");
 }
 public void StripableTextItalic2()
 {
     var st = new StripableText("<i>O</i>");
     Assert.AreEqual(st.Pre, "<i>");
     Assert.AreEqual(st.Post, "</i>");
     Assert.AreEqual(st.StrippedText, "O");
 }
 public void StripableTextFont()
 {
     var st = new StripableText("<font color=\"red\">Hi!</font>");
     Assert.AreEqual(st.Pre, "<font color=\"red\">");
     Assert.AreEqual(st.Post, "!</font>");
     Assert.AreEqual(st.StrippedText, "Hi");
 }
 public void StripableTextFontDontTouch()
 {
     var st = new StripableText("{MAN} Hi, how are you today!");
     Assert.AreEqual(st.Pre, "");
     Assert.AreEqual(st.Post, "!");
     Assert.AreEqual(st.StrippedText, "{MAN} Hi, how are you today");
 }
 public void StripableTextAss()
 {
     var st = new StripableText("{\\an9}Hi!");
     Assert.AreEqual(st.Pre, "{\\an9}");
     Assert.AreEqual(st.Post, "!");
     Assert.AreEqual(st.StrippedText, "Hi");
 }
 public void StripableOnlyText()
 {
     var st = new StripableText("H");
     Assert.AreEqual(st.Pre, "");
     Assert.AreEqual(st.Post, "");
     Assert.AreEqual(st.StrippedText, "H");
 }
예제 #7
0
        public void FixUppercaseIInsideWords()
        {
            string fixAction = _language.FixUppercaseIInsideLowercaseWord;
            int uppercaseIsInsideLowercaseWords = 0;
            //            bool isLineContinuation = false;
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                string oldText = p.Text;

                Match match = ReAfterLowercaseLetter.Match(p.Text);
                while (match.Success)
                {
                    if (!(match.Index > 1 && p.Text.Substring(match.Index - 1, 2) == "Mc")) // irish names, McDonalds etc.
                    {
                        if (p.Text[match.Index + 1] == 'I')
                        {
                            if (AllowFix(p, fixAction))
                            {
                                p.Text = p.Text.Substring(0, match.Index + 1) + "l";
                                if (match.Index + 2 < oldText.Length)
                                    p.Text += oldText.Substring(match.Index + 2);

                                uppercaseIsInsideLowercaseWords++;
                                _totalFixes++;
                                AddFixToListView(p, fixAction, oldText, p.Text);
                            }
                        }
                    }
                    match = match.NextMatch();
                }

                StripableText st = new StripableText(p.Text);
                match = ReBeforeLowercaseLetter.Match(st.StrippedText);
                while (match.Success)
                {
                    string word = GetWholeWord(st.StrippedText, match.Index);
                    if (!IsName(word))
                    {
                        if (AllowFix(p, fixAction))
                        {
                            if (word.ToLower() == "internal" ||
                                word.ToLower() == "island" ||
                                word.ToLower() == "islands")
                            {
                            }
                            else if (match.Index == 0)
                            {  // first letter in paragraph

                                //too risky! - perhaps if periods is fixed at the same time... or too complicated!?
                                //if (isLineContinuation)
                                //{
                                //    st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                //    p.Text = st.MergedString;
                                //    uppercaseIsInsideLowercaseWords++;
                                //    _totalFixes++;
                                //    AddFixToListView(p, fixAction, oldText, p.Text);
                                //}
                            }
                            else
                            {
                                if (match.Index > 2 && st.StrippedText[match.Index - 1] == ' ')
                                {
                                    if ((Utilities.AllLettersAndNumbers + ",").Contains(st.StrippedText[match.Index - 2].ToString()))
                                    {
                                        string secondLetter = string.Empty;
                                        if (match.Length >= 2)
                                            secondLetter = match.Value.Substring(1, 1);
                                        if (Utilities.LowerCaseVowels.Contains(secondLetter.ToLower()))
                                        {
                                            st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                            p.Text = st.MergedString;
                                            uppercaseIsInsideLowercaseWords++;
                                            _totalFixes++;
                                            AddFixToListView(p, fixAction, oldText, p.Text);
                                        }
                                    }
                                }
                                else if (match.Index > Environment.NewLine.Length + 1 && Environment.NewLine.Contains(st.StrippedText[match.Index - 1].ToString()))
                                {
                                    if ((Utilities.AllLettersAndNumbers + ",").Contains(st.StrippedText[match.Index - (Environment.NewLine.Length + 1)].ToString()))
                                    {
                                        string next = string.Empty;
                                        if (match.Length >= 2)
                                            next = match.Value.Substring(1, 1);

                                        if (Utilities.LowerCaseVowels.Contains(next))
                                        {
                                            st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                            p.Text = st.MergedString;
                                            uppercaseIsInsideLowercaseWords++;
                                            _totalFixes++;
                                            AddFixToListView(p, fixAction, oldText, p.Text);
                                        }
                                    }
                                }
                                else if (match.Index > 1 && ((st.StrippedText[match.Index - 1] == '\"') || (st.StrippedText[match.Index - 1] == '\'') ||
                                                             (st.StrippedText[match.Index - 1] == '>') || (st.StrippedText[match.Index - 1] == '-')))
                                {
                                }
                                else
                                {
                                    string before = string.Empty;
                                    string after = string.Empty;
                                    if (match.Index > 0)
                                        before = st.StrippedText.Substring(match.Index - 1, 1);
                                    if (match.Index < st.StrippedText.Length - 2)
                                        after = st.StrippedText.Substring(match.Index + 1, 1);
                                    if (before.Length == 1 && before != before.ToLower() && after.Length == 1 && after != after.ToUpper() &&
                                        !Utilities.LowerCaseVowels.Contains(before.ToLower()) && !Utilities.LowerCaseVowels.Contains(after.ToLower()))
                                    {
                                        st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "i");
                                        p.Text = st.MergedString;
                                        uppercaseIsInsideLowercaseWords++;
                                        _totalFixes++;
                                        AddFixToListView(p, fixAction, oldText, p.Text);
                                    }
                                    else
                                    {
                                        if ("‘’¡¿„“()[]♪'. ".Contains(before) && !(Utilities.LowerCaseVowels).Contains(after.ToLower()))
                                        {
                                        }
                                        else
                                        {
                                            st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                            p.Text = st.MergedString;
                                            uppercaseIsInsideLowercaseWords++;
                                            _totalFixes++;
                                            AddFixToListView(p, fixAction, oldText, p.Text);
                                        }
                                    }
                                }
                            }

                        }
                    }
                    match = match.NextMatch();
                }

                //isLineContinuation = p.Text.Length > 0 && Utilities.GetLetters(true, true, false).Contains(p.Text[p.Text.Length - 1].ToString());
            }
            if (uppercaseIsInsideLowercaseWords > 0)
                LogStatus(_language.FixUppercaseIInsindeLowercaseWords, string.Format(_language.XUppercaseIsFoundInsideLowercaseWords, uppercaseIsInsideLowercaseWords));
        }
예제 #8
0
        public static string FixStartWithUppercaseLetterAfterParagraph(Paragraph p, Paragraph prev, Encoding encoding, string language)
        {
            if (p.Text != null && p.Text.Length > 1)
            {
                string text = p.Text;
                string pre = string.Empty;
                if (text.Length > 4 && text.StartsWith("<i> "))
                {
                    pre = "<i> ";
                    text = text.Substring(4);
                }
                if (text.Length > 3 && text.StartsWith("<i>"))
                {
                    pre = "<i>";
                    text = text.Substring(3);
                }
                if (text.Length > 4 && text.StartsWith("<I> "))
                {
                    pre = "<I> ";
                    text = text.Substring(4);
                }
                if (text.Length > 3 && text.StartsWith("<I>"))
                {
                    pre = "<I>";
                    text = text.Substring(3);
                }
                if (text.Length > 2 && text.StartsWith("♪"))
                {
                    pre = pre + "♪";
                    text = text.Substring(1);
                }
                if (text.Length > 2 && text.StartsWith(" "))
                {
                    pre = pre + " ";
                    text = text.Substring(1);
                }
                if (text.Length > 2 && text.StartsWith("♫"))
                {
                    pre = pre + "♫";
                    text = text.Substring(1);
                }
                if (text.Length > 2 && text.StartsWith(" "))
                {
                    pre = pre + " ";
                    text = text.Substring(1);
                }

                string oldText = p.Text;
                string firstLetter = text.Substring(0, 1);

                string prevText = " .";
                if (prev != null)
                    prevText = Utilities.RemoveHtmlTags(prev.Text);

                bool isPrevEndOfLine = IsPrevoiusTextEndOfParagraph(prevText);
                if (prevText == " .")
                    isPrevEndOfLine = true;
                if ((!text.StartsWith("www.") && !text.StartsWith("http:") && !text.StartsWith("https:")) &&
                    (firstLetter != firstLetter.ToUpper() || IsTurkishLittleI(firstLetter, encoding, language)) &&
                    !"0123456789".Contains(firstLetter) &&
                    isPrevEndOfLine)
                {
                    bool isMatchInKnowAbbreviations = language == "en" &&
                        (prevText.EndsWith(" o.r.") ||
                         prevText.EndsWith(" a.m.") ||
                         prevText.EndsWith(" p.m."));

                    if (!isMatchInKnowAbbreviations)
                    {
                        if (IsTurkishLittleI(firstLetter, encoding, language))
                            p.Text = pre + GetTurkishUppercaseLetter(firstLetter, encoding) + text.Substring(1);
                        else if (language == "en" && (text.StartsWith("l ") || text.StartsWith("l-I") || text.StartsWith("ls ") || text.StartsWith("lnterested") ||
                                                      text.StartsWith("lsn't ") || text.StartsWith("ldiot") || text.StartsWith("ln") || text.StartsWith("lm") ||
                                                      text.StartsWith("ls") || text.StartsWith("lt") || text.StartsWith("lf ") || text.StartsWith("lc") || text.StartsWith("l'm ")) || text.StartsWith("l am ")) // l > I
                            p.Text = pre + "I" + text.Substring(1);
                        else
                            p.Text = pre + firstLetter.ToUpper() + text.Substring(1);
                    }
                }
            }

            if (p.Text != null && p.Text.Contains(Environment.NewLine))
            {
                string[] arr = p.Text.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
                if (arr.Length == 2 && arr[1].Length > 1)
                {
                    string text = arr[1];
                    string pre = string.Empty;
                    if (text.Length > 4 && text.StartsWith("<i> "))
                    {
                        pre = "<i> ";
                        text = text.Substring(4);
                    }
                    if (text.Length > 3 && text.StartsWith("<i>"))
                    {
                        pre = "<i>";
                        text = text.Substring(3);
                    }
                    if (text.Length > 4 && text.StartsWith("<I> "))
                    {
                        pre = "<I> ";
                        text = text.Substring(4);
                    }
                    if (text.Length > 3 && text.StartsWith("<I>"))
                    {
                        pre = "<I>";
                        text = text.Substring(3);
                    }
                    if (text.Length > 2 && text.StartsWith("♪"))
                    {
                        pre = pre + "♪";
                        text = text.Substring(1);
                    }
                    if (text.Length > 2 && text.StartsWith(" "))
                    {
                        pre = pre + " ";
                        text = text.Substring(1);
                    }
                    if (text.Length > 2 && text.StartsWith("♫"))
                    {
                        pre = pre + "♫";
                        text = text.Substring(1);
                    }
                    if (text.Length > 2 && text.StartsWith(" "))
                    {
                        pre = pre + " ";
                        text = text.Substring(1);
                    }

                    string oldText = p.Text;
                    string firstLetter = text.Substring(0, 1);
                    string prevText = Utilities.RemoveHtmlTags(arr[0]);
                    bool isPrevEndOfLine = IsPrevoiusTextEndOfParagraph(prevText);
                    if ((!text.StartsWith("www.") && !text.StartsWith("http:") && !text.StartsWith("https:")) &&
                        (firstLetter != firstLetter.ToUpper() || IsTurkishLittleI(firstLetter, encoding, language)) &&
                        !prevText.EndsWith("...") &&
                        isPrevEndOfLine)
                    {
                        bool isMatchInKnowAbbreviations = language == "en" &&
                            (prevText.EndsWith(" o.r.") ||
                             prevText.EndsWith(" a.m.") ||
                             prevText.EndsWith(" p.m."));

                        if (!isMatchInKnowAbbreviations)
                        {
                            if (IsTurkishLittleI(firstLetter, encoding, language))
                                text = pre + GetTurkishUppercaseLetter(firstLetter, encoding) + text.Substring(1);
                            else if (language == "en" && (text.StartsWith("l ") || text.StartsWith("l-I") || text.StartsWith("ls ") || text.StartsWith("lnterested") ||
                                                     text.StartsWith("lsn't ") || text.StartsWith("ldiot") || text.StartsWith("ln") || text.StartsWith("lm") ||
                                                     text.StartsWith("ls") || text.StartsWith("lt") || text.StartsWith("lf ") || text.StartsWith("lc") || text.StartsWith("l'm ")) || text.StartsWith("l am ")) // l > I
                                text = pre + "I" + text.Substring(1);
                            else
                                text = pre + firstLetter.ToUpper() + text.Substring(1);
                            p.Text = arr[0] + Environment.NewLine + text;
                        }
                    }

                    arr = p.Text.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
                    if ((arr[0].StartsWith("-") || arr[0].StartsWith("<i>-")) &&
                        (arr[1].StartsWith("-") || arr[1].StartsWith("<i>-")) &&
                        !arr[0].StartsWith("--") && !arr[0].StartsWith("<i>--") &&
                        !arr[1].StartsWith("--") && !arr[1].StartsWith("<i>--"))
                    {
                        if (isPrevEndOfLine && arr[1].StartsWith("<i>- ") && arr[1].Length > 6)
                        {
                            p.Text = arr[0] + Environment.NewLine + "<i>- " + arr[1].Substring(5, 1).ToUpper() + arr[1].Remove(0, 6);
                        }
                        else if (isPrevEndOfLine && arr[1].StartsWith("- ") && arr[1].Length > 3)
                        {
                            p.Text = arr[0] + Environment.NewLine + "- " + arr[1].Substring(2, 1).ToUpper() + arr[1].Remove(0, 3);
                        }
                        arr = p.Text.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');

                        prevText = " .";
                        if (prev != null && p.StartTime.TotalMilliseconds - 10000 < prev.EndTime.TotalMilliseconds)
                            prevText = Utilities.RemoveHtmlTags(prev.Text);
                        bool isPrevLineEndOfLine = IsPrevoiusTextEndOfParagraph(prevText);
                        if (prevText == " .")
                            isPrevEndOfLine = true;
                        if (isPrevLineEndOfLine && arr[0].StartsWith("<i>- ") && arr[0].Length > 6)
                        {
                            p.Text = "<i>- " + arr[0].Substring(5, 1).ToUpper() + arr[0].Remove(0, 6) + Environment.NewLine + arr[1];
                        }
                        else if (isPrevLineEndOfLine && arr[0].StartsWith("- ") && arr[0].Length > 3)
                        {
                            p.Text =  "- " + arr[0].Substring(2, 1).ToUpper() + arr[0].Remove(0, 3) + Environment.NewLine + arr[1];
                        }

                    }
                }
            }

            if (p.Text.Length > 4)
            {
                int len = 0;
                int indexOfNewLine = p.Text.IndexOf(Environment.NewLine + " -", 1);
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "- <i> ♪", 1);
                    len = "- <i> ♪".Length;
                }
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "-", 1);
                    len = "-".Length;
                }
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i>-", 1);
                    len = "<i>-".Length;
                }
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i> -", 1);
                    len = "<i> -".Length;
                }
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "♪ -", 1);
                    len = "♪ -".Length;
                }
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "♪ <i> -", 1);
                    len = "♪ <i> -".Length;
                }
                if (indexOfNewLine == -1)
                {
                    indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "♪ <i>-", 1);
                    len = "♪ <i>-".Length;
                }

                if (indexOfNewLine > 0)
                {
                    string text = p.Text.Substring(indexOfNewLine + len);
                    StripableText st = new StripableText(text);

                    if (st.StrippedText.Length > 0 && IsTurkishLittleI(st.StrippedText, encoding, language) && !st.Pre.EndsWith("[") && !st.Pre.Contains("..."))
                    {
                        text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, GetTurkishUppercaseLetter(st.StrippedText, encoding)) + st.Post;
                        p.Text = p.Text.Remove(indexOfNewLine + len).Insert(indexOfNewLine + len, text);
                    }
                    else if (st.StrippedText.Length > 0 && st.StrippedText[0] != char.ToUpper(st.StrippedText[0]) && !st.Pre.EndsWith("[") && !st.Pre.Contains("..."))
                    {
                        text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, st.StrippedText[0].ToString().ToUpper()) + st.Post;
                        p.Text = p.Text.Remove(indexOfNewLine + len).Insert(indexOfNewLine + len, text);
                    }
                }
            }
            return p.Text;
        }
예제 #9
0
        public void FixMissingPeriodsAtEndOfLine()
        {
            string fixAction = _language.FixMissingPeriodAtEndOfLine;
            int missigPeriodsAtEndOfLine = 0;
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                Paragraph next = _subtitle.GetParagraphOrDefault(i + 1);
                string nextText = string.Empty;
                if (next != null)
                    nextText = Utilities.RemoveHtmlTags(next.Text).TrimStart('-', '"', '„').TrimStart();
                string tempNoHtml = Utilities.RemoveHtmlTags(p.Text).TrimEnd();

                if (IsOneLineUrl(p.Text) || p.Text.Contains("♪") || p.Text.Contains("♫") || p.Text.EndsWith("'"))
                {
                    ; // ignore urls
                }
                else if (!string.IsNullOrEmpty(nextText) && next != null &&
                    next.Text.Length > 0 &&
                    Utilities.UppercaseLetters.Contains(nextText[0].ToString()) &&
                    tempNoHtml.Length > 0 &&
                    (!",.!?:;>-])♪♫…".Contains(tempNoHtml[tempNoHtml.Length - 1].ToString())))
                {
                    string tempTrimmed = tempNoHtml.TrimEnd().TrimEnd(new char[] { '\'', '"', '“', '”' }).TrimEnd();
                    if (!tempNoHtml.EndsWith(")") && !tempNoHtml.EndsWith("]") && !tempNoHtml.EndsWith("*") && !tempNoHtml.EndsWith("#") && !tempNoHtml.EndsWith("¶") && // hear impaired
                        !tempTrimmed.EndsWith(".") && !tempTrimmed.EndsWith("!") && !tempTrimmed.EndsWith("?"))
                    {
                        if (p.Text != p.Text.ToUpper())
                        {
                            //don't end the sentence if the next word is an I word as they're always capped.
                            if (!next.Text.StartsWith("I ") && !next.Text.StartsWith("I'"))
                            {
                                //test to see if the first word of the next line is a name
                                if (!IsName(next.Text.Split(" .,-?!:;\"()[]{}|<>/+\r\n".ToCharArray())[0]))
                                {
                                    if (AllowFix(p, fixAction))
                                    {
                                        string oldText = p.Text;
                                        if (p.Text.EndsWith(">"))
                                        {
                                            int lastLT = p.Text.LastIndexOf("<");
                                            if (lastLT > 0)
                                                p.Text = p.Text.Insert(lastLT, ".");
                                        }
                                        else
                                        {
                                            if (p.Text.EndsWith("“") && tempNoHtml.StartsWith("„"))
                                                p.Text = p.Text.TrimEnd('“') + ".“";
                                            else if (p.Text.EndsWith("\"") && tempNoHtml.StartsWith("\""))
                                                p.Text = p.Text.TrimEnd('"') + ".\"";
                                            else
                                                p.Text += ".";
                                        }
                                        if (p.Text != oldText)
                                        {
                                            _totalFixes++;
                                            missigPeriodsAtEndOfLine++;
                                            AddFixToListView(p, fixAction, oldText, p.Text);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                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.UppercaseLetters.Contains(st.StrippedText[0].ToString()))
                        {
                            if (AllowFix(p, fixAction))
                            {
                                int j = p.Text.Length - 1;
                                while (j >= 0 && !(".!?¿¡").Contains(p.Text[j].ToString()))
                                    j--;
                                string endSign = ".";
                                if (j >= 0 && p.Text[j] == '¿')
                                    endSign = "?";
                                if (j >= 0 && p.Text[j] == '¡')
                                    endSign = "!";

                                string oldText = p.Text;
                                _totalFixes++;
                                missigPeriodsAtEndOfLine++;
                                p.Text += endSign;
                                AddFixToListView(p, fixAction, oldText, p.Text);
                            }
                        }
                    }
                }

                if (p.Text.Length > 4)
                {
                    int indexOfNewLine = p.Text.IndexOf(Environment.NewLine + " -", 3);
                    if (indexOfNewLine == -1)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "-", 3);
                    if (indexOfNewLine == -1)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i>-", 3);
                    if (indexOfNewLine == -1)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i> -", 3);
                    if (indexOfNewLine > 0)
                    {
                        if (Configuration.Settings.General.UppercaseLetters.Contains(p.Text[indexOfNewLine - 1].ToString().ToUpper()))
                        {
                            if (AllowFix(p, fixAction))
                            {
                                string oldText = p.Text;

                                string text = p.Text.Substring(0, indexOfNewLine);
                                StripableText st = new StripableText(text);
                                if (st.Pre.TrimEnd().EndsWith("¿")) // Spanish ¿
                                    p.Text = p.Text.Insert(indexOfNewLine, "?");
                                else if (st.Pre.TrimEnd().EndsWith("¡")) // Spanish ¡
                                    p.Text = p.Text.Insert(indexOfNewLine, "!");
                                else
                                    p.Text = p.Text.Insert(indexOfNewLine, ".");

                                _totalFixes++;
                                missigPeriodsAtEndOfLine++;
                                AddFixToListView(p, fixAction, oldText, p.Text);
                            }
                        }
                    }
                }
            }

            if (missigPeriodsAtEndOfLine > 0)
                LogStatus(_language.AddPeriods, string.Format(_language.XPeriodsAdded, missigPeriodsAtEndOfLine));
        }
예제 #10
0
        private void MergeLinesWithContinuation()
        {
            var temp = new Subtitle();
            bool skipNext = false;
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                if (!skipNext)
                {
                    Paragraph next = _subtitle.GetParagraphOrDefault(i + 1);

                    bool merge = !(p.Text.Contains(Environment.NewLine) || next == null);

                    if (merge && (p.Text.TrimEnd().EndsWith("!") || 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)))
                            merge = false;
                    }

                    if (merge && (p.Text.Length >= Configuration.Settings.General.SubtitleLineMaximumLength - 5 || next.Text.Length >= Configuration.Settings.General.SubtitleLineMaximumLength - 5))
                        merge = false;

                    if (merge)
                    {
                        temp.Paragraphs.Add(new Paragraph { Text = p.Text + Environment.NewLine + next.Text });
                        skipNext = true;
                    }
                    else
                    {
                        temp.Paragraphs.Add(new Paragraph(p));
                    }
                }
                else
                {
                    skipNext = false;
                }
            }
            _subtitle = temp;
        }
예제 #11
0
        private string FixCasing(string text, string lastLine, List<string> namesEtc)
        {
            string original = text;
            if (radioButtonNormal.Checked)
            {
                if (checkBoxOnlyAllUpper.Checked && text != text.ToUpper())
                    return text;

                if (text.Length > 1)
                {
                    // first all to lower
                    text = text.ToLower().Trim();
                    while (text.Contains("  "))
                        text = text.Replace("  ", " ");
                    text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                    text = text.Replace(Environment.NewLine + " ", Environment.NewLine);

                    var st = new StripableText(text);
                    st.FixCasing(namesEtc, false, true, true, lastLine); // fix all casing but names (that's a seperate option)
                    text = st.MergedString;
                }
            }
            else if (radioButtonUppercase.Checked)
            {
                StripableText st = new StripableText(text);
                text = st.Pre + st.StrippedText.ToUpper() + st.Post;
                text = text.Replace("<I>", "<i>");
                text = text.Replace("</I>", "</i>");
                text = text.Replace("<B>", "<b>");
                text = text.Replace("</B>", "</b>");
                text = text.Replace("<U>", "<u>");
                text = text.Replace("<U>", "</u>");
                text = text.Replace("<FONT COLOR>", "<font color>");
                text = text.Replace("</FONT>", "</font>");
            }
            else if (radioButtonLowercase.Checked)
            {
                text = text.ToLower();
            }
            if (original != text)
                _noOfLinesChanged++;
            return text;
        }
예제 #12
0
        private void FixStartWithUppercaseLetterAfterParagraph()
        {
            string fixAction1 = _language.FixFirstLetterToUppercaseAfterParagraph + " ";
            string fixAction2 = _language.FixFirstLetterToUppercaseAfterParagraph;
            int fixedStartWithUppercaseLetterAfterParagraphTicked = 0;
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);

                if (p.Text != null && p.Text.Length > 1)
                {
                    string text = p.Text;
                    string pre = string.Empty;
                    if (text.Length > 4 && text.StartsWith("<i> "))
                    {
                        pre = "<i> ";
                        text = text.Substring(4);
                    }
                    if (text.Length > 3 && text.StartsWith("<i>"))
                    {
                        pre = "<i>";
                        text = text.Substring(3);
                    }
                    if (text.Length > 4 && text.StartsWith("<I> "))
                    {
                        pre = "<I> ";
                        text = text.Substring(4);
                    }
                    if (text.Length > 3 && text.StartsWith("<I>"))
                    {
                        pre = "<I>";
                        text = text.Substring(3);
                    }
                    if (text.Length > 2 && text.StartsWith("♪"))
                    {
                        pre = pre + "♪";
                        text = text.Substring(1);
                    }
                    if (text.Length > 2 && text.StartsWith(" "))
                    {
                        pre = pre + " ";
                        text = text.Substring(1);
                    }
                    if (text.Length > 2 && text.StartsWith("♫"))
                    {
                        pre = pre + "♫";
                        text = text.Substring(1);
                    }
                    if (text.Length > 2 && text.StartsWith(" "))
                    {
                        pre = pre + " ";
                        text = text.Substring(1);
                    }

                    string oldText = p.Text;
                    string firstLetter = text.Substring(0, 1);

                    string prevText = " .";
                    if (prev != null)
                        prevText = Utilities.RemoveHtmlTags(prev.Text);

                    bool isPrevEndOfLine = IsPrevoiusTextEndOfParagraph(prevText);
                    if (prevText == " .")
                        isPrevEndOfLine = true;
                    if (!text.StartsWith("www.") &&
                        (firstLetter != firstLetter.ToUpper() || IsTurkishLittleI(firstLetter)) &&
                        !"0123456789".Contains(firstLetter) &&
                        isPrevEndOfLine)
                    {
                        bool isMatchInKnowAbbreviations = _autoDetectGoogleLanguage == "en" &&
                            (prevText.EndsWith(" o.r.") ||
                             prevText.EndsWith(" a.m.") ||
                             prevText.EndsWith(" p.m."));

                        if (!isMatchInKnowAbbreviations && AllowFix(p, fixAction1))
                        {
                            if (IsTurkishLittleI(firstLetter))
                                p.Text = pre + GetTurkishUppercaseLetter(firstLetter) + text.Substring(1);
                            else
                                p.Text = pre + firstLetter.ToUpper() + text.Substring(1);
                            _totalFixes++;
                            fixedStartWithUppercaseLetterAfterParagraphTicked++;
                            AddFixToListView(p, fixAction1, oldText, p.Text);
                        }
                    }
                }

                if (p.Text != null && p.Text.Contains(Environment.NewLine))
                {
                    string[] arr = p.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    if (arr.Length == 2 && arr[1].Length > 1)
                    {
                        string text = arr[1];
                        string pre = string.Empty;
                        if (text.Length > 4 && text.StartsWith("<i> "))
                        {
                            pre = "<i> ";
                            text = text.Substring(4);
                        }
                        if (text.Length > 3 && text.StartsWith("<i>"))
                        {
                            pre = "<i>";
                            text = text.Substring(3);
                        }
                        if (text.Length > 4 && text.StartsWith("<I> "))
                        {
                            pre = "<I> ";
                            text = text.Substring(4);
                        }
                        if (text.Length > 3 && text.StartsWith("<I>"))
                        {
                            pre = "<I>";
                            text = text.Substring(3);
                        }
                        if (text.Length > 2 && text.StartsWith("♪"))
                        {
                            pre = pre + "♪";
                            text = text.Substring(1);
                        }
                        if (text.Length > 2 && text.StartsWith(" "))
                        {
                            pre = pre + " ";
                            text = text.Substring(1);
                        }
                        if (text.Length > 2 && text.StartsWith("♫"))
                        {
                            pre = pre + "♫";
                            text = text.Substring(1);
                        }
                        if (text.Length > 2 && text.StartsWith(" "))
                        {
                            pre = pre + " ";
                            text = text.Substring(1);
                        }

                        string oldText = p.Text;
                        string firstLetter = text.Substring(0, 1);
                        string prevText = Utilities.RemoveHtmlTags(arr[0]);
                        bool isPrevEndOfLine = IsPrevoiusTextEndOfParagraph(prevText);
                        if (!text.StartsWith("www.") &&
                            (firstLetter != firstLetter.ToUpper() || IsTurkishLittleI(firstLetter)) &&
                            !prevText.EndsWith("...") &&
                            isPrevEndOfLine)
                        {
                            bool isMatchInKnowAbbreviations = _autoDetectGoogleLanguage == "en" &&
                                (prevText.EndsWith(" o.r.") ||
                                 prevText.EndsWith(" a.m.") ||
                                 prevText.EndsWith(" p.m."));

                            if (!isMatchInKnowAbbreviations && AllowFix(p, fixAction2))
                            {
                                if (IsTurkishLittleI(firstLetter))
                                    text = pre + GetTurkishUppercaseLetter(firstLetter) + text.Substring(1);
                                else
                                    text = pre + firstLetter.ToUpper() + text.Substring(1);
                                _totalFixes++;
                                fixedStartWithUppercaseLetterAfterParagraphTicked++;
                                p.Text = arr[0] + Environment.NewLine + text;
                                AddFixToListView(p, fixAction2, oldText, p.Text);
                            }
                        }
                    }
                }

                if (p.Text.Length > 4)
                {
                    int indexOfNewLine = p.Text.IndexOf(Environment.NewLine + " -", 1);
                    if (indexOfNewLine == -1)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "-", 1);
                    if (indexOfNewLine == -1)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i>-", 1);
                    if (indexOfNewLine == -1)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i> -", 1);
                    if (indexOfNewLine > 0)
                    {
                        string text = p.Text.Substring(indexOfNewLine + 2);
                        StripableText st = new StripableText(text);

                        if (st.StrippedText.Length > 0 && IsTurkishLittleI(st.StrippedText) && !st.Pre.EndsWith("[") && !st.Pre.Contains("..."))
                        {
                            text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, GetTurkishUppercaseLetter(st.StrippedText)) + st.Post;

                            if (AllowFix(p, fixAction2))
                            {
                                string oldText = p.Text;
                                p.Text = p.Text.Remove(indexOfNewLine + 2).Insert(indexOfNewLine + 2, text);
                                _totalFixes++;
                                fixedStartWithUppercaseLetterAfterParagraphTicked++;
                                AddFixToListView(p, fixAction2, oldText, p.Text);
                            }
                        }
                        else if (st.StrippedText.Length > 0 && st.StrippedText[0].ToString() != st.StrippedText[0].ToString().ToUpper() && !st.Pre.EndsWith("[") && !st.Pre.Contains("..."))
                        {
                            text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, st.StrippedText[0].ToString().ToUpper()) + st.Post;

                            if (AllowFix(p, fixAction2))
                            {
                                string oldText = p.Text;
                                p.Text = p.Text.Remove(indexOfNewLine + 2).Insert(indexOfNewLine + 2, text);
                                _totalFixes++;
                                fixedStartWithUppercaseLetterAfterParagraphTicked++;
                                AddFixToListView(p, fixAction2, oldText, p.Text);
                            }
                        }
                    }

                }
            }
            if (fixedStartWithUppercaseLetterAfterParagraphTicked > 0)
                LogStatus(_language.StartWithUppercaseLetterAfterParagraph, fixedStartWithUppercaseLetterAfterParagraphTicked.ToString());
        }
        internal string RemoveTextFromHearImpaired(string text, string prevText)
        {
            if (checkBoxRemoveWhereContains.Checked && comboBoxRemoveIfTextContains.Text.Length > 0 && text.Contains(comboBoxRemoveIfTextContains.Text))
            {
                return string.Empty;
            }

            string oldText = text;
            text = RemoveColon(text, prevText);
            string pre = " >-\"'‘`´♪¿¡.…—";
            string post = " -\"'`´♪.!?:…—";
            if (checkBoxRemoveTextBetweenCustomTags.Checked)
            {
                pre = pre.Replace(comboBoxCustomStart.Text, string.Empty);
                post = post.Replace(comboBoxCustomEnd.Text, string.Empty);
            }
            var st = new StripableText(text, pre, post);
            var sb = new StringBuilder();
            string[] parts = st.StrippedText.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            int lineNumber = 0;
            bool removedDialogInFirstLine = false;
            int noOfNamesRemoved = 0;
            int noOfNamesRemovedNotInLineOne = 0;
            foreach (string s in parts)
            {
                StripableText stSub = new StripableText(s, pre, post);
                if (!StartAndEndsWithHearImpariedTags(stSub.StrippedText))
                {
                    if (removedDialogInFirstLine && stSub.Pre.Contains("- "))
                        stSub.Pre = stSub.Pre.Replace("- ", string.Empty);

                    string newText = stSub.StrippedText;

                    newText = RemoveHearImpairedTags(newText);

                    if (stSub.StrippedText.Length - newText.Length > 2)
                    {
                        string removedText = GetRemovedString(stSub.StrippedText, newText);
                        if (!IsHIDescription(removedText))
                        {
                            noOfNamesRemoved++;
                            if (lineNumber > 0)
                                noOfNamesRemovedNotInLineOne++;
                        }
                    }
                    sb.AppendLine(stSub.Pre + newText + stSub.Post);
                }
                else
                {
                    if (!IsHIDescription(stSub.StrippedText))
                    {
                        noOfNamesRemoved++;
                        if (lineNumber > 0)
                            noOfNamesRemovedNotInLineOne++;
                    }

                    if (st.Pre.Contains("- ") && lineNumber == 0)
                    {
                        st.Pre = st.Pre.Replace("- ", string.Empty);
                        removedDialogInFirstLine = true;
                    }

                    if (st.Pre.Contains("<i>") && stSub.Post.Contains("</i>"))
                        st.Pre = st.Pre.Replace("<i>", string.Empty);

                    if (s.Contains("<i>") && !s.Contains("</i>") && st.Post.Contains("</i>"))
                        st.Post = st.Post.Replace("</i>", string.Empty);
                }
                lineNumber++;
            }

            text = st.Pre + sb.ToString().Trim() + st.Post;
            text = text.Replace("<i></i>", string.Empty).Trim();
            text = RemoveColon(text, prevText);
            text = RemoveLineIfAllUppercase(text);
            text = RemoveHearImpairedtagsInsideLine(text);
            if (checkBoxRemoveInterjections.Checked)
                text = RemoveInterjections(text);

            st = new StripableText(text, " >-\"'‘`´♪¿¡.…—", " -\"'`´♪.!?:…—");
            text = st.StrippedText;
            if (StartAndEndsWithHearImpariedTags(text))
            {
                text = RemoveStartEndTags(text);
            }


            text = RemoveHearImpairedTags(text);

            // fix 3 lines to two liners - if only two lines
            if (noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 2)
            {
                string[] a = Utilities.RemoveHtmlTags(text).Replace(" ", string.Empty).Split("!?.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (a.Length == 2)
                {
                    StripableText temp = new StripableText(text);
                    temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " ");
                    int splitIndex = temp.StrippedText.LastIndexOf("!");
                    if (splitIndex == -1)
                        splitIndex = temp.StrippedText.LastIndexOf("?");
                    if (splitIndex == -1)
                        splitIndex = temp.StrippedText.LastIndexOf(".");
                    if (splitIndex > 0)
                    {
                        text = temp.Pre + temp.StrippedText.Insert(splitIndex + 1, Environment.NewLine) + temp.Post;
                    }
                }
            }

            if (!text.StartsWith("-") && noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1)
            {
                string[] arr = text.Split(Environment.NewLine.ToCharArray());
                string part0 = arr[0].Trim().Replace("</i>", string.Empty).Trim();
                if (!part0.EndsWith(",") && (!part0.EndsWith("-") || noOfNamesRemovedNotInLineOne > 0))
                {
                    if (part0.Length > 0 && ".!?".Contains(part0.Substring(part0.Length - 1)))
                    {
                        if (noOfNamesRemovedNotInLineOne > 0)
                        {
                            if (!st.Pre.Contains("-"))
                                text = "- " + text.Replace(Environment.NewLine, Environment.NewLine + "- ");
                            if (!text.Contains(Environment.NewLine + "-") && !text.Contains(Environment.NewLine + "<i>-"))
                                text = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(text))
                text = st.Pre + text + st.Post;

            if (oldText.Trim().StartsWith("- ") &&
                (oldText.Contains(Environment.NewLine + "- ") || oldText.Contains(Environment.NewLine + " - ")) &&
                text != null && !text.Contains(Environment.NewLine))
            {
                text = text.TrimStart().TrimStart('-').TrimStart();
            }

            if (oldText != text)
            {
                // insert spaces before "-"
                text = text.Replace(Environment.NewLine + "- <i>", Environment.NewLine + "<i>- ");
                text = text.Replace(Environment.NewLine + "-<i>", Environment.NewLine + "<i>- ");
                if (text.StartsWith("-") && text.Length > 2 && text[1] != ' ' && text[1] != '-')
                    text = text.Insert(1, " ");
                if (text.StartsWith("<i>-") && text.Length > 5 && text[4] != ' ' && text[4] != '-')
                    text = text.Insert(4, " ");
                if (text.Contains(Environment.NewLine + "-"))
                {
                    int index = text.IndexOf(Environment.NewLine + "-");
                    if (index + 4 < text.Length && text[index + Environment.NewLine.Length + 1] != ' ' && text[index + Environment.NewLine.Length + 1] != '-')
                        text = text.Insert(index + Environment.NewLine.Length + 1, " ");
                }
                if (text.Contains(Environment.NewLine + "<i>-"))
                {
                    int index = text.IndexOf(Environment.NewLine + "<i>-");
                    if (index + 5 < text.Length && text[index + Environment.NewLine.Length + 4] != ' ' && text[index + Environment.NewLine.Length + 4] != '-')
                        text = text.Insert(index + Environment.NewLine.Length + 4, " ");
                }
            }
            return text.Trim();
        }
예제 #14
0
        private void FixStartWithUppercaseLetterAfterPeriodInsideParagraph()
        {
            string fixAction = _language.StartWithUppercaseLetterAfterPeriodInsideParagraph;
            int noOfFixes = 0;
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                string oldText = p.Text;
                StripableText st = new StripableText(p.Text);
                if (p.Text.Length > 3)
                {
                    string text = st.StrippedText.Replace("  ", " ");
                    int start = text.IndexOfAny(".!?".ToCharArray());
                    while (start != -1 && start < text.Length)
                    {
                        if (start > 0 && Utilities.IsInteger(text[start - 1].ToString()))
                        {
                            // ignore periods after a number
                        }
                        else if (start + 4 < text.Length && text[start + 1] == ' ')
                        {
                            if (!IsAbbreviation(text, start))
                            {
                                StripableText subText = new StripableText(text.Substring(start + 2));
                                if (subText.StrippedText.Length > 0 && IsTurkishLittleI(subText.StrippedText, _encoding, Language))
                                {
                                    if (subText.StrippedText.Length > 1 && !(subText.Pre.Contains("'") && subText.StrippedText.StartsWith("s")))
                                    {
                                        text = text.Substring(0, start + 2) + subText.Pre + GetTurkishUppercaseLetter(subText.StrippedText, _encoding) + subText.StrippedText.Substring(1) + subText.Post;
                                        if (AllowFix(p, fixAction))
                                        {
                                            p.Text = st.Pre + text + st.Post;
                                        }
                                    }
                                }
                                else if (subText.StrippedText.Length > 0 && Configuration.Settings.General.UppercaseLetters.ToLower().Contains(subText.StrippedText[0].ToString()))
                                {
                                    if (subText.StrippedText.Length > 1 && !(subText.Pre.Contains("'") && subText.StrippedText.StartsWith("s")))
                                    {
                                        text = text.Substring(0, start + 2) + subText.Pre + subText.StrippedText[0].ToString().ToUpper() + subText.StrippedText.Substring(1) + subText.Post;
                                        if (AllowFix(p, fixAction))
                                        {
                                            p.Text = st.Pre + text + st.Post;
                                        }
                                    }
                                }
                            }
                        }
                        start += 4;
                        if (start < text.Length)
                            start = text.IndexOfAny(".!?".ToCharArray(), start);
                    }
                }

                if (oldText != p.Text)
                {
                    noOfFixes++;
                    _totalFixes++;
                    AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            if (noOfFixes > 0)
                LogStatus(_language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString());
        }
        private string RemoveInterjections(string text)
        {
            string oldText = text;

            if (_interjectionList == null)
            {
                string[] arr = Configuration.Settings.Tools.Interjections.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                _interjectionList = new List<string>();
                foreach (string s in arr)
                {
                    if (!_interjectionList.Contains(s))
                        _interjectionList.Add(s);
                    string lower = s.ToLower();
                    if (!_interjectionList.Contains(lower))
                        _interjectionList.Add(lower);
                }
                _interjectionList.Sort(new Comparison<string>(CompareLength));
            }

            bool doRepeat = true;
            while (doRepeat)
            {
                doRepeat = false;
                foreach (string s in _interjectionList)
                {
                    if (text.Contains(s))
                    {
                        var regex = new Regex("\\b" + s + "\\b");
                        Match match = regex.Match(text);
                        if (match.Success)
                        {
                            int index = match.Index;
                            string temp = text.Remove(index, s.Length);

                            string pre = string.Empty;
                            if (index > 0)
                                doRepeat = true;

                            bool removeAfter = true;

                            if (temp.Length > index - s.Length + 3 && index > s.Length)
                            {
                                if (temp.Substring(index - s.Length + 1, 3) == ", !")
                                {
                                    temp = temp.Remove(index - s.Length + 1, 2);
                                    removeAfter = false;
                                }
                                else if (temp.Substring(index - s.Length + 1, 3) == ", ?")
                                {
                                    temp = temp.Remove(index - s.Length + 1, 2);
                                    removeAfter = false;
                                }
                                else if (temp.Substring(index - s.Length + 1, 3) == ", .")
                                {
                                    temp = temp.Remove(index - s.Length + 1, 2);
                                    removeAfter = false;
                                }
                            }
                            if (removeAfter && temp.Length > index - s.Length + 2 && index > s.Length)
                            {
                                if (temp.Substring(index - s.Length, 3) == ", !")
                                {
                                    temp = temp.Remove(index - s.Length, 2);
                                    removeAfter = false;
                                }
                                else if (temp.Substring(index - s.Length, 3) == ", ?")
                                {
                                    temp = temp.Remove(index - s.Length, 2);
                                    removeAfter = false;
                                }
                                else if (temp.Substring(index - s.Length, 3) == ", .")
                                {
                                    temp = temp.Remove(index - s.Length, 2);
                                    removeAfter = false;
                                }
                            }
                            if (removeAfter && temp.Length > index - s.Length + 2 && index > s.Length)
                            {
                                if (temp.Substring(index - s.Length + 1, 2) == "-!")
                                {
                                    temp = temp.Remove(index - s.Length + 1, 1);
                                    removeAfter = false;
                                }
                                else if (temp.Substring(index - s.Length + 1, 2) == "-?")
                                {
                                    temp = temp.Remove(index - s.Length + 1, 1);
                                    removeAfter = false;
                                }
                                else if (temp.Substring(index - s.Length + 1, 2) == "-.")
                                {
                                    temp = temp.Remove(index - s.Length + 1, 1);
                                    removeAfter = false;
                                }
                            }

                            if (removeAfter)
                            {
                                if (index == 0)
                                {
                                    if (!string.IsNullOrEmpty(temp) && temp.StartsWith("-"))
                                        temp = temp.Remove(0, 1).Trim();
                                }
                                else if (index == 3 && !string.IsNullOrEmpty(temp) && temp.StartsWith("<i>-"))
                                {
                                    temp = temp.Remove(3, 1);
                                }
                                else if (index > 0)
                                {
                                    pre = text.Substring(0, index);
                                    temp = temp.Remove(0, index);
                                    if (pre.EndsWith("-") && temp.StartsWith("-"))
                                        temp = temp.Remove(0, 1);
                                    if (pre.EndsWith("- ") && temp.StartsWith("-"))
                                        temp = temp.Remove(0, 1);
                                }

                                while (temp.Length > 0 && (temp.StartsWith(" ") || temp.StartsWith(",") || temp.StartsWith(".") || temp.StartsWith("!") || temp.StartsWith("?")))
                                {
                                    temp = temp.Remove(0, 1);
                                    doRepeat = true;
                                }
                                if (temp.Length > 0 && s[0].ToString() != s[0].ToString().ToLower())
                                {
                                    temp = temp.Remove(0, 1).Insert(0, temp[0].ToString().ToUpper());
                                    doRepeat = true;
                                }
                                temp = pre + temp;
                            }

                            if (temp.EndsWith(Environment.NewLine + "- "))
                                temp = temp.Remove(temp.Length - 4, 4);

                            var st = new StripableText(temp);
                            if (st.StrippedText.Length == 0)
                                return string.Empty;

                            if (!temp.Contains(Environment.NewLine) && text.Contains(Environment.NewLine) && temp.StartsWith("-"))
                                temp = temp.Remove(0,1).Trim();

                            text = temp;
                        }
                    }
                }
            }
            string[] lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (text != oldText && lines.Length == 2)
            {
                if (lines[0] == "-" && lines[1] == "-")
                    return string.Empty;
                if (lines[0].StartsWith("-") && lines[0].Length > 1 && lines[1].Trim() == "-")
                    return lines[0].Remove(0, 1).Trim();
                if (lines[1].StartsWith("-") && lines[1].Length > 1 && lines[0].Trim() == "-")
                    return lines[1].Remove(0, 1).Trim();
                if (lines[0].Length > 1 && (lines[1] == "-") || lines[1] == "." || lines[1] == "!" || lines[1] == "?")
                {
                    if (oldText.Contains(Environment.NewLine + "-") && lines[0].StartsWith("-"))
                        lines[0] = lines[0].Remove(0, 1);
                    return lines[0].Trim();
                }
            }

            return text;
        }
예제 #16
0
        private void FixSpanishInvertedLetter(string mark, string inverseMark, Paragraph p, Paragraph last, ref bool wasLastLineClosed, int i, string fixAction, ref int fixCount)
        {
            if (p.Text.Contains(mark))
            {
                bool skip = false;
                if (last != null && p.Text.Contains(mark) && !p.Text.Contains(inverseMark) && last.Text.Contains(inverseMark) && !last.Text.Contains(mark))
                    skip = true;

                if (!skip && Utilities.CountTagInText(p.Text, mark) == Utilities.CountTagInText(p.Text, inverseMark) &&
                    Utilities.RemoveHtmlTags(p.Text).TrimStart(inverseMark[0]).Contains(inverseMark) == false &&
                    Utilities.RemoveHtmlTags(p.Text).TrimEnd(mark[0]).Contains(mark) == false)
                {
                    skip = true;
                }

                if (!skip)
                {
                    int startIndex = 0;
                    int markIndex = p.Text.IndexOf(mark);
                    if (!wasLastLineClosed && ((p.Text.IndexOf("!") > 0 && p.Text.IndexOf("!") < markIndex) ||
                                               (p.Text.IndexOf("?") > 0 && p.Text.IndexOf("?") < markIndex) ||
                                               (p.Text.IndexOf(".") > 0 && p.Text.IndexOf(".") < markIndex)))
                        wasLastLineClosed = true;
                    while (markIndex > 0 && startIndex < p.Text.Length)
                    {
                        int inverseMarkIndex = p.Text.IndexOf(inverseMark, startIndex);
                        if (wasLastLineClosed && (inverseMarkIndex == -1 || inverseMarkIndex > markIndex))
                        {
                            if (AllowFix(p, fixAction))
                            {
                                int j = markIndex - 1;

                                while (j > startIndex && (p.Text[j] == '.' || p.Text[j] == '!' || p.Text[j] == '?'))
                                    j--;

                                while (j > startIndex &&
                                       (p.Text[j] != '.' || IsSpanishAbbreviation(p.Text, j)) &&
                                       p.Text[j] != '!' &&
                                       p.Text[j] != '?' &&
                                       !(j > 3 && p.Text.Substring(j - 3, 3) == Environment.NewLine + "-") &&
                                       !(j > 4 && p.Text.Substring(j - 4, 4) == Environment.NewLine + " -") &&
                                       !(j > 6 && p.Text.Substring(j - 6, 6) == Environment.NewLine + "<i>-"))
                                    j--;

                                if (".!?".Contains(p.Text[j].ToString()))
                                {
                                    j++;
                                }
                                if (j + 3 < p.Text.Length && p.Text.Substring(j + 1, 2) == Environment.NewLine)
                                {
                                    j += 3;
                                }
                                else if (j + 2 < p.Text.Length && p.Text.Substring(j, 2) == Environment.NewLine)
                                {
                                    j += 2;
                                }
                                if (j >= startIndex)
                                {
                                    string part = p.Text.Substring(j, markIndex - j + 1);

                                    string speaker = string.Empty;
                                    int speakerEnd = part.IndexOf(")");
                                    if (part.StartsWith("(") && speakerEnd > 0 && speakerEnd < part.IndexOf(mark))
                                    {
                                        while (Environment.NewLine.Contains(part[speakerEnd + 1].ToString()))
                                            speakerEnd++;
                                        speaker = part.Substring(0, speakerEnd + 1);
                                        part = part.Substring(speakerEnd + 1);
                                    }
                                    speakerEnd = part.IndexOf("]");
                                    if (part.StartsWith("[") && speakerEnd > 0 && speakerEnd < part.IndexOf(mark))
                                    {
                                        while (Environment.NewLine.Contains(part[speakerEnd + 1].ToString()))
                                            speakerEnd++;
                                        speaker = part.Substring(0, speakerEnd + 1);
                                        part = part.Substring(speakerEnd + 1);
                                    }

                                    var st = new StripableText(part);
                                    if (j == 0 && mark == "!" && st.Pre == "¿" && Utilities.CountTagInText(p.Text, mark) == 1 && Utilities.RemoveHtmlTags(p.Text).EndsWith(mark))
                                    {
                                        p.Text = inverseMark + p.Text;
                                    }
                                    else if (j == 0 && mark == "?" && st.Pre == "¡" && Utilities.CountTagInText(p.Text, mark) == 1 && Utilities.RemoveHtmlTags(p.Text).EndsWith(mark))
                                    {
                                        p.Text = inverseMark + p.Text;
                                    }
                                    else
                                    {
                                        string temp = inverseMark;
                                        int addToIndex = 0;
                                        while (p.Text.Length > markIndex + 1 && p.Text[markIndex + 1].ToString() == mark &&
                                            Utilities.CountTagInText(p.Text, mark) > Utilities.CountTagInText(p.Text + temp, inverseMark))
                                        {
                                            temp += inverseMark;
                                            st.Post += mark;
                                            markIndex++;
                                            addToIndex++;
                                        }

                                        p.Text = p.Text.Remove(j, markIndex - j + 1).Insert(j, speaker + st.Pre + temp + st.StrippedText + st.Post);
                                        markIndex += addToIndex;
                                    }

                                }
                            }
                        }
                        else if (last != null && !wasLastLineClosed && inverseMarkIndex == p.Text.IndexOf(mark) && !last.Text.Contains(inverseMark))
                        {
                            string lastOldtext = last.Text;
                            int idx = last.Text.Length - 2;
                            while (idx > 0 && (last.Text.Substring(idx, 2) != ". ") && (last.Text.Substring(idx, 2) != "! ") && (last.Text.Substring(idx, 2) != "? "))
                                idx--;

                            last.Text = last.Text.Insert(idx, inverseMark);
                            fixCount++;
                            _totalFixes++;
                            AddFixToListView(last, fixAction, lastOldtext, last.Text);
                        }

                        startIndex = markIndex + 2;
                        if (startIndex < p.Text.Length)
                            markIndex = p.Text.IndexOf(mark, startIndex);
                        else
                            markIndex = -1;
                        wasLastLineClosed = true;
                    }
                }
                if (p.Text.EndsWith(mark + "...") && p.Text.Length > 4)
                {
                    p.Text = p.Text.Remove(p.Text.Length - 4, 4) + "..." + mark;
                }
            }
            else if (Utilities.CountTagInText(p.Text, inverseMark) == 1)
            {
                int idx = p.Text.IndexOf(inverseMark);
                while (idx < p.Text.Length && !".!?".Contains(p.Text[idx].ToString()))
                {
                    idx++;
                }
                if (idx < p.Text.Length)
                {
                    p.Text = p.Text.Insert(idx, mark);
                    if (p.Text.Contains("¡¿") && p.Text.Contains("!?"))
                        p.Text.Replace("!?", "?!");
                    if (p.Text.Contains("¿¡") && p.Text.Contains("?!"))
                        p.Text.Replace("?!", "!?");
                }
            }
        }
 public void StripableOnlyPre()
 {
     var st = new StripableText("(");
     Assert.AreEqual(st.Pre, "(");
     Assert.AreEqual(st.Post, string.Empty);
     Assert.AreEqual(st.StrippedText, string.Empty);
 }
예제 #18
0
        private void FixStartWithUppercaseLetterAfterColon()
        {
            string fixAction = _language.StartWithUppercaseLetterAfterColon;
            int noOfFixes = 0;
            listViewFixes.BeginUpdate();
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                Paragraph last = _subtitle.GetParagraphOrDefault(i - 1);
                string oldText = p.Text;
                int skipCount = 0;

                if (last != null)
                {
                    string lastText = Utilities.RemoveHtmlTags(last.Text);
                    if (lastText.EndsWith(":") || lastText.EndsWith(";"))
                    {
                        var st = new StripableText(p.Text);
                        if (st.StrippedText.Length > 0 && st.StrippedText[0] != char.ToUpper(st.StrippedText[0]))
                            p.Text = st.Pre + char.ToUpper(st.StrippedText[0]) + st.StrippedText.Substring(1) + st.Post;
                    }
                }

                if (oldText.Contains(":") || oldText.Contains(";"))
                {
                    bool lastWasColon = false;
                    for (int j = 0; j < p.Text.Length; j++)
                    {
                        string s = p.Text[j].ToString();
                        if (s == ":" || s == ";")
                        {
                            lastWasColon = true;
                        }
                        else if (lastWasColon)
                        {
                            if (skipCount > 0)
                                skipCount--;
                            else if (p.Text.Substring(j).StartsWith("<i>"))
                                skipCount = 2;
                            else if (p.Text.Substring(j).StartsWith("<b>"))
                                skipCount = 2;
                            else if (p.Text.Substring(j).StartsWith("<u>"))
                                skipCount = 2;
                            else if (p.Text.Substring(j).StartsWith("<font ") && p.Text.Substring(j).Contains(">"))
                                skipCount = p.Text.Substring(j).IndexOf(">") - p.Text.Substring(j).IndexOf("<font ");
                            else if (IsTurkishLittleI(s, _encoding, Language))
                            {
                                p.Text = p.Text.Remove(j, 1).Insert(j, GetTurkishUppercaseLetter(s, _encoding));
                                lastWasColon = false;
                            }
                            else if (s != s.ToUpper())
                            {
                                p.Text = p.Text.Remove(j, 1).Insert(j, s.ToUpper());
                                lastWasColon = false;
                            }
                            else if (!(" " + Environment.NewLine).Contains(s))
                                lastWasColon = false;
                        }
                    }
                }

                if (oldText != p.Text)
                {
                    noOfFixes++;
                    _totalFixes++;
                    AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            listViewFixes.EndUpdate();
            if (noOfFixes > 0)
                LogStatus(_language.StartWithUppercaseLetterAfterColon, noOfFixes.ToString());
        }
        private string RemoveColon(string text, string prevText)
        {
            if (!checkBoxRemoveTextBeforeColon.Checked)
                return text;

            if (text.IndexOf(":") < 0)
                return text;

            // House 7x01 line 52: and she would like you to do three things:
            // Okay or remove???
            if (text.IndexOf(':') > 0 && text.IndexOf(':') == text.Length - 1 && text != text.ToUpper())
                return text;

            string newText = string.Empty;
            string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            int noOfNames = 0;
            int count = 0;
            bool removedInFirstLine = false;
            bool removedInSecondLine = false;
            foreach (string s in parts)
            {
                int indexOfColon = s.IndexOf(":");
                if (indexOfColon > 0)
                {
                    string pre = s.Substring(0, indexOfColon);
                    if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
                    {
                        newText = newText + Environment.NewLine + s;
                        newText = newText.Trim();
                    }
                    else
                    {
                        StripableText st = new StripableText(pre);
                        if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && removedInFirstLine && Utilities.CountTagInText(s, ":") == 1 &&
                            !newText.EndsWith(".") && !newText.EndsWith("!") && !newText.EndsWith("?") && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
                            s != s.ToUpper())
                        {
                            if (pre.Contains("<i>") && s.Contains("</i>"))
                                newText = newText + Environment.NewLine + "<i>" + s;
                            else if (pre.Contains("<b>") && s.Contains("</b>"))
                                newText = newText + Environment.NewLine + "<b>" + s;
                            else if (pre.Contains("[") && s.Contains("]"))
                                newText = newText + Environment.NewLine + "[" + s;
                            else if (pre.Contains("(") && s.EndsWith(")"))
                                newText = newText + Environment.NewLine + "(" + s;
                            else
                                newText = newText + Environment.NewLine + s;
                        }
                        else if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && indexOfColon > 15 && s.Substring(0, indexOfColon).Contains(" ") && Utilities.CountTagInText(s, ":") == 1 &&
                            !newText.EndsWith(".") && !newText.EndsWith("!") && !newText.EndsWith("?") && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
                            s != s.ToUpper())
                        {
                            if (pre.Contains("<i>") && s.Contains("</i>"))
                                newText = newText + Environment.NewLine + "<i>" + s;
                            else if (pre.Contains("<b>") && s.Contains("</b>"))
                                newText = newText + Environment.NewLine + "<b>" + s;
                            else if (pre.Contains("[") && s.Contains("]"))
                                newText = newText + Environment.NewLine + "[" + s;
                            else if (pre.Contains("(") && s.EndsWith(")"))
                                newText = newText + Environment.NewLine + "(" + s;
                            else
                                newText = newText + Environment.NewLine + s;
                        }
                        else if (Utilities.CountTagInText(s, ":") == 1)
                        {
                            bool remove = true;
                            if (indexOfColon > 0 && indexOfColon < s.Length - 1)
                            {
                                if ("1234567890".Contains(s.Substring(indexOfColon - 1, 1)) && "1234567890".Contains(s.Substring(indexOfColon + 1, 1)))
                                    remove = false;
                            }
                            if (s.StartsWith("Previously on") || s.StartsWith("<i>Previously on"))
                                remove = false;

                            if (remove && checkBoxColonSeparateLine.Checked)
                            {
                                if (indexOfColon == s.Length - 1 || s.Substring(indexOfColon + 1).StartsWith(Environment.NewLine))
                                    remove = true;
                                else
                                    remove = false;
                            }

                            if (remove)
                            {
                                string content = s.Substring(indexOfColon + 1).Trim();
                                if (content.Length > 0)
                                {
                                    if (pre.Contains("<i>") && content.Contains("</i>"))
                                        newText = newText + Environment.NewLine + "<i>" + content;
                                    else if (pre.Contains("<b>") && content.Contains("</b>"))
                                        newText = newText + Environment.NewLine + "<b>" + content;
                                    else if (pre.Contains("[") && content.Contains("]"))
                                        newText = newText + Environment.NewLine + "[" + content;
                                    else if (pre.Contains("(") && content.EndsWith(")"))
                                        newText = newText + Environment.NewLine + "(" + content;
                                    else
                                        newText = newText + Environment.NewLine + content;

                                    if (count == 0)
                                        removedInFirstLine = true;
                                    else if (count == 1)
                                        removedInSecondLine = true;
                                }
                                newText = newText.Trim();

                                if (text.StartsWith("(") && newText.EndsWith(")") && !newText.Contains("("))
                                    newText = newText.TrimEnd(')');
                                else if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
                                    newText = "<i>" + newText;
                                else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
                                    newText = "<b>" + newText;

                                if (!IsHIDescription(st.StrippedText))
                                    noOfNames++;
                            }
                            else
                            {
                                newText = newText + Environment.NewLine + s;
                                newText = newText.Trim();
                                if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
                                    newText = "<i>" + newText;
                                else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
                                    newText = "<b>" + newText;
                            }
                        }
                        else
                        {
                            string s2 = s;
                            for (int k = 0; k < 2; k++)
                            {
                                if (s2.Contains(":"))
                                {
                                    int colonIndex = s2.IndexOf(":");
                                    string start = s2.Substring(0, colonIndex);

                                    bool doContinue = true;
                                    if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && start != start.ToUpper())
                                        doContinue = false;
                                    if (doContinue)
                                    {

                                        int periodIndex = start.LastIndexOf(". ");
                                        int questIndex = start.LastIndexOf("? ");
                                        int exclaIndex = start.LastIndexOf("! ");
                                        int endIndex = periodIndex;
                                        if (endIndex == -1 || questIndex > endIndex)
                                            endIndex = questIndex;
                                        if (endIndex == -1 || exclaIndex > endIndex)
                                            endIndex = exclaIndex;
                                        if (colonIndex > 0 && colonIndex < s2.Length - 1)
                                        {
                                            if ("1234567890".Contains(s2.Substring(colonIndex - 1, 1)) && "1234567890".Contains(s2.Substring(colonIndex + 1, 1)))
                                                endIndex = -10;
                                        }
                                        if (endIndex == -1)
                                            s2 = s2.Remove(0, colonIndex - endIndex);
                                        else if (endIndex > 0)
                                            s2 = s2.Remove(endIndex + 1, colonIndex - endIndex);
                                    }

                                    if (count == 0)
                                        removedInFirstLine = true;
                                    else if (count == 1)
                                        removedInSecondLine = true;
                                }
                            }
                            newText = newText + Environment.NewLine + s2;
                            newText = newText.Trim();
                        }
                    }
                }
                else
                {
                    newText = newText + Environment.NewLine + s;
                    newText = newText.Trim();

                    if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
                        newText = "<i>" + newText;
                    else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
                        newText = "<b>" + newText;
                }
                count++;
            }
            newText = newText.Trim();
            if (noOfNames > 0 && Utilities.CountTagInText(newText, Environment.NewLine) == 1)
            {
                int indexOfDialogChar = newText.IndexOf('-');
                bool insertDash = true;
                string[] arr = newText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
                {
                    string arr0 = new StripableText(arr[0]).StrippedText;
                    string arr1 = new StripableText(arr[1]).StrippedText;

                    //line continuation?
                    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;
                    }

                    if (arr0.Length > 0 && arr1.Length > 1 && !(arr[0].EndsWith(".") || arr[0].EndsWith("!") || arr[0].EndsWith("?") || arr[0].EndsWith("</i>")) &&
                        !(new StripableText(arr[1]).Pre.Contains("-")))
                    {
                        insertDash = false;
                    }

                    if (removedInFirstLine && !removedInSecondLine && !text.StartsWith("-") && !text.StartsWith("<i>-"))
                    {
                        if (insertDash && removedInFirstLine && (arr[1].StartsWith("-") || arr[1].StartsWith("<i>-")))
                            insertDash = true;
                        else
                            insertDash = false;
                    }
                }

                if (insertDash)
                {
                    if (indexOfDialogChar < 0 || indexOfDialogChar > 4)
                    {
                        StripableText st = new StripableText(newText, "", "");
                        newText = st.Pre + "- " + st.StrippedText + st.Post;
                    }

                    int indexOfNewLine = newText.IndexOf(Environment.NewLine);
                    string second = newText.Substring(indexOfNewLine).Trim();
                    indexOfDialogChar = second.IndexOf('-');
                    if (indexOfDialogChar < 0 || indexOfDialogChar > 6)
                    {
                        StripableText st = new StripableText(second, "", "");
                        second = st.Pre + "- " + st.StrippedText + st.Post;
                        newText = newText.Remove(indexOfNewLine) + Environment.NewLine + second;
                    }
                }
            }
            else if (!newText.Contains(Environment.NewLine) && newText.Contains("-"))
            {
                StripableText st = new StripableText(newText);
                if (st.Pre.Contains("-"))
                    newText = st.Pre.Replace("-", string.Empty) + st.StrippedText + st.Post;
            }
            else if (Utilities.CountTagInText(newText, Environment.NewLine) == 1 && removedInFirstLine == false && removedInSecondLine == true)
            {
                string noTags = Utilities.RemoveHtmlTags(newText, true).Trim();
                bool insertDash = noTags.StartsWith("-") && Utilities.CountTagInText(noTags, "-") == 1;
                if (insertDash)
                {
                    if (newText.Contains(Environment.NewLine + "<i>"))
                        newText = newText.Replace(Environment.NewLine + "<i>", Environment.NewLine + "<i>- ");
                    else
                        newText = newText.Replace(Environment.NewLine, Environment.NewLine + "- ");
                }
            }
            if (text.Contains("<i>") && !newText.Contains("<i>") && newText.EndsWith("</i>"))
                newText = "<i>" + newText;
            return newText;
        }
예제 #20
0
        public void FixHyphens()
        {
            string fixAction = _language.FixHyphen;
            int iFixes = 0;
            for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = _subtitle.Paragraphs[i];
                string text = p.Text;

                if (text.Trim().StartsWith("-") ||
                    text.Trim().StartsWith("<i>-") ||
                    text.Trim().StartsWith("<i> -") ||
                    text.Trim().StartsWith("<I>-") ||
                    text.Trim().StartsWith("<I> -") ||
                    text.Contains(Environment.NewLine + "-") ||
                    text.Contains(Environment.NewLine + " -") ||
                    text.Contains(Environment.NewLine + "<i>-") ||
                    text.Contains(Environment.NewLine + "<i> -") ||
                    text.Contains(Environment.NewLine + "<I>-") ||
                    text.Contains(Environment.NewLine + "<I> -"))
                {
                    Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);

                    if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-"))
                    {
                        var lines = Utilities.RemoveHtmlTags(p.Text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        int startHyphenCount = 0;
                        foreach (string line in lines)
                        {
                            if (line.Trim().StartsWith("-"))
                                startHyphenCount++;
                        }
                        if (startHyphenCount == 1)
                        {
                            string oldText = p.Text;

                            bool remove = true;

                            string[] parts = Utilities.RemoveHtmlTags(text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                            if (parts.Length == 2)
                            {
                                if (parts[0].Trim().StartsWith("-") && parts[1].Contains(": "))
                                    remove = false;
                                if (parts[1].Trim().StartsWith("-") && parts[0].Contains(": "))
                                    remove = false;
                            }

                            if (remove)
                            {
                                int idx = text.IndexOf("-");
                                var st = new StripableText(text);
                                if (idx < 5 && st.Pre.Length >= idx)
                                {
                                    text = text.Remove(idx, 1).TrimStart();
                                    idx = text.IndexOf("-");
                                    st = new StripableText(text);
                                    if (idx < 5 && idx >= 0 && st.Pre.Length >= idx)
                                    {
                                        text = text.Remove(idx, 1).TrimStart();
                                        st = new StripableText(text);
                                    }
                                    idx = text.IndexOf("-");
                                    if (idx < 5 && idx >= 0 && st.Pre.Length >= idx)
                                        text = text.Remove(idx, 1).TrimStart();

                                    text = text.Replace("  ", " ");
                                    text = text.Replace("> ", ">");
                                    text = text.Replace(" <", "<");
                                }
                                else
                                {
                                    int idxNL = text.IndexOf(Environment.NewLine);
                                    if (idxNL > 0)
                                    {
                                        idx = text.IndexOf("-", idxNL);
                                        if (idx >= 0 && idxNL + 5 > idxNL)
                                        {
                                            text = text.Remove(idx, 1).TrimStart().Replace(Environment.NewLine + " ", Environment.NewLine);

                                            idx = text.IndexOf("-", idxNL);
                                            if (idx >= 0 && idxNL + 5 > idxNL)
                                            {
                                                text = text.Remove(idx, 1).TrimStart();

                                                text = text.Replace("  ", " ");
                                                text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                                                text = text.Replace("> ", ">");
                                                text = text.Replace(" <", "<");
                                            }
                                        }
                                    }
                                }

                                if (text != oldText)
                                {
                                    if (AllowFix(p, fixAction))
                                    {
                                        p.Text = text;
                                        iFixes++;
                                        _totalFixes++;
                                        AddFixToListView(p, fixAction, oldText, p.Text);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (text.StartsWith("<font "))
                {
                    Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);
                    if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-"))
                    {
                        string oldText = p.Text;
                        var st = new StripableText(text);
                        if (st.Pre.EndsWith("-") || st.Pre.EndsWith("- "))
                        {
                            text = st.Pre.TrimEnd().TrimEnd('-').TrimEnd() + st.StrippedText + st.Post;
                        }
                        if (text != oldText)
                        {
                            if (AllowFix(p, fixAction))
                            {
                                p.Text = text;
                                iFixes++;
                                _totalFixes++;
                                AddFixToListView(p, fixAction, oldText, p.Text);
                            }
                        }
                    }
                }
            }
            if (iFixes > 0)
                LogStatus(_language.FixHyphens, string.Format(_language.XHyphensFixed, iFixes));
        }
예제 #21
0
        private void GeneratePreview()
        {
            Cursor = Cursors.WaitCursor;
            listViewFixes.BeginUpdate();
            listViewFixes.Items.Clear();
            foreach (Paragraph p in _subtitle.Paragraphs)
            {
                string text = p.Text;
                foreach (ListViewItem item in listViewNames.Items)
                {
                    string name = item.SubItems[1].Text;

                    string textNoTags = Utilities.RemoveHtmlTags(text);
                    if (textNoTags != textNoTags.ToUpper())
                    {
                        if (item.Checked && text != null && text.ToLower().Contains(name.ToLower()) && name.Length > 1 && name != name.ToLower())
                        {
                            var st = new StripableText(text);
                            st.FixCasing(new List<string> {name}, true, false, false, string.Empty);
                            text = st.MergedString;
                        }
                    }
                }
                if (text != p.Text)
                    AddToPreviewListView(p, text);
            }
            listViewFixes.EndUpdate();
            groupBoxLinesFound.Text = string.Format(Configuration.Settings.Language.ChangeCasingNames.LinesFoundX, listViewFixes.Items.Count);
            Cursor = Cursors.Default;
        }