@@ -382,13 +382,13 @@ public virtual string InnerText
382382 var sb = new StringBuilder ( ) ;
383383 int depthLevel = 0 ;
384384 string name = this . Name ;
385-
385+
386386 if ( name != null )
387387 {
388- name = name . ToLowerInvariant ( ) ;
388+ bool isDisplayScriptingText = string . Equals ( name , "head" , StringComparison . OrdinalIgnoreCase )
389+ || string . Equals ( name , "script" , StringComparison . OrdinalIgnoreCase )
390+ || string . Equals ( name , "style" , StringComparison . OrdinalIgnoreCase ) ;
389391
390- bool isDisplayScriptingText = ( name == "head" || name == "script" || name == "style" ) ;
391-
392392 InternalInnerText ( sb , isDisplayScriptingText , depthLevel ) ;
393393 }
394394 else
@@ -1997,7 +1997,7 @@ public virtual void WriteTo(TextWriter outText, int level = 0)
19971997 if ( _ownerdocument . OptionOutputAsXml )
19981998 {
19991999 var commentNode = ( HtmlCommentNode ) this ;
2000- if ( ! _ownerdocument . BackwardCompatibility && commentNode . Comment . ToLowerInvariant ( ) . StartsWith ( "<!doctype" ) )
2000+ if ( ! _ownerdocument . BackwardCompatibility && commentNode . Comment . StartsWith ( "<!doctype" , StringComparison . OrdinalIgnoreCase ) )
20012001 {
20022002 outText . Write ( commentNode . Comment ) ;
20032003 }
@@ -2636,6 +2636,8 @@ public void AddClass(string name)
26362636 AddClass ( name , false ) ;
26372637 }
26382638
2639+ private static readonly char [ ] spaceSeparator = { ' ' } ;
2640+
26392641 /// <summary>
26402642 /// Adds one or more classes to this node.
26412643 /// </summary>
@@ -2644,26 +2646,26 @@ public void AddClass(string name)
26442646 public void AddClass ( string name , bool throwError )
26452647 {
26462648 var classAttributes = Attributes . AttributesWithName ( "class" ) ;
2649+ var isEmpty = true ;
26472650
2648- if ( ! IsEmpty ( classAttributes ) )
2651+ foreach ( HtmlAttribute att in classAttributes )
26492652 {
2650- foreach ( HtmlAttribute att in classAttributes )
2651- {
2652- // Check class solo, check class in First with other class, check Class no first.
2653- if ( att . Value != null && att . Value . Split ( ' ' ) . ToList ( ) . Any ( x => x . Equals ( name ) ) )
2654- {
2655- if ( throwError )
2656- {
2657- throw new Exception ( HtmlDocument . HtmlExceptionClassExists ) ;
2658- }
2659- }
2660- else
2653+ isEmpty = false ;
2654+ // Check class solo, check class in First with other class, check Class no first.
2655+ if ( att . Value != null && Array . IndexOf ( att . Value . Split ( spaceSeparator ) , name ) != - 1 )
2656+ {
2657+ if ( throwError )
26612658 {
2662- SetAttributeValue ( att . Name , att . Value + " " + name ) ;
2659+ throw new Exception ( HtmlDocument . HtmlExceptionClassExists ) ;
26632660 }
26642661 }
2662+ else
2663+ {
2664+ SetAttributeValue ( att . Name , att . Value + " " + name ) ;
2665+ }
26652666 }
2666- else
2667+
2668+ if ( isEmpty )
26672669 {
26682670 HtmlAttribute attribute = _ownerdocument . CreateAttribute ( "class" , name ) ;
26692671 Attributes . Append ( attribute ) ;
@@ -2731,7 +2733,7 @@ public void RemoveClass(string name, bool throwError)
27312733 {
27322734 Attributes . Remove ( att ) ;
27332735 }
2734- else if ( att . Value != null && att . Value . Split ( ' ' ) . ToList ( ) . Any ( x => x . Equals ( name ) ) )
2736+ else if ( att . Value != null && att . Value . Split ( ' ' ) . Contains ( name ) )
27352737 {
27362738 string [ ] classNames = att . Value . Split ( ' ' ) ;
27372739
0 commit comments