44using System . Linq ;
55using System . Text ;
66using System . Text . RegularExpressions ;
7+ using Nikse . SubtitleEdit . Core . Common ;
78
89namespace Nikse . SubtitleEdit . PluginLogic
910{
1011 public class NarratorArtist : Artist
1112 {
12- private static readonly Regex _regexColonNonWord = new Regex ( ":\\ B" , RegexOptions . Compiled | RegexOptions . ExplicitCapture ) ;
13+ private static readonly Regex RegexColonNonWord = new ( ":\\ B" , RegexOptions . Compiled | RegexOptions . ExplicitCapture ) ;
1314
1415 /// <summary>
1516 /// This regex pattern is written to not capture characters inside html tags
1617 /// </summary>
17- private static readonly Regex _regexFirtCharNotTag = new Regex ( "(?<!<)\\ w" , RegexOptions . Compiled | RegexOptions . ExplicitCapture ) ;
18+ private static readonly Regex RegexFirtCharNotTag = new ( "(?<!<)\\ w" , RegexOptions . Compiled | RegexOptions . ExplicitCapture ) ;
1819
1920 /// <summary>
2021 /// Narrator ignore words
@@ -35,10 +36,11 @@ public override void Paint(Subtitle subtitle)
3536 {
3637 var p = paragraphs [ i ] ;
3738 string text = p . Text ;
38- if ( _regexColonNonWord . IsMatch ( text ) )
39+ if ( RegexColonNonWord . IsMatch ( text ) )
3940 {
4041 text = ProcessText ( text ) ;
4142 }
43+
4244 if ( text . Length != p . Text . Length )
4345 {
4446 p . Text = text ;
@@ -49,13 +51,13 @@ public override void Paint(Subtitle subtitle)
4951 private string ProcessText ( string text )
5052 {
5153 char [ ] trimChars = { '"' , '\\ ' } ;
52- string [ ] lines = text . SplitToLines ( ) ;
53- for ( int i = 0 ; i < lines . Length ; i ++ )
54+ var lines = text . SplitToLines ( ) ;
55+ for ( int i = 0 ; i < lines . Count ; i ++ )
5456 {
5557 string line = lines [ i ] ;
5658
5759 //TODO: if text contains 2 hearing text
58- string lineNoTags = HtmlUtils . RemoveTags ( line , true ) . TrimEnd ( trimChars ) . TrimEnd ( ) ;
60+ string lineNoTags = HtmlUtil . RemoveHtmlTags ( line , true ) . TrimEnd ( trimChars ) . TrimEnd ( ) ;
5961
6062 if ( ! ShouldApplyColor ( lineNoTags , isFirstLine : i == 0 ) )
6163 {
@@ -68,7 +70,7 @@ private string ProcessText(string text)
6870
6971 string preText = line . Substring ( 0 , colonIdx ) ;
7072
71- string firstChr = _regexFirtCharNotTag . Match ( preText ) . Value ;
73+ string firstChr = RegexFirtCharNotTag . Match ( preText ) . Value ;
7274 if ( string . IsNullOrEmpty ( firstChr ) )
7375 {
7476 continue ;
@@ -87,8 +89,8 @@ private string ProcessText(string text)
8789 line = line . Insert ( 0 , preText ) ;
8890
8991 lines [ i ] = line ;
90-
9192 }
93+
9294 // re-construct text
9395 return string . Join ( Environment . NewLine , lines ) ;
9496 }
@@ -105,7 +107,7 @@ private bool ShouldApplyColor(string textNoTags, bool isFirstLine)
105107
106108 // (foobar) foobar: hello world!
107109 string pre = textNoTags . Substring ( 0 , colonIdx ) . TrimStart ( ) ;
108- if ( pre . ContainsAny ( new [ ] { ')' , ']' } ) )
110+ if ( pre . Contains ( new [ ] { ')' , ']' } ) )
109111 {
110112 return false ;
111113 }
@@ -137,4 +139,4 @@ private bool ShouldApplyColor(string textNoTags, bool isFirstLine)
137139 return true ;
138140 }
139141 }
140- }
142+ }
0 commit comments