@@ -369,13 +369,13 @@ public virtual string InnerText
369369 var sb = new StringBuilder ( ) ;
370370 int depthLevel = 0 ;
371371 string name = this . Name ;
372-
372+
373373 if ( name != null )
374374 {
375- name = name . ToLowerInvariant ( ) ;
375+ bool isDisplayScriptingText = string . Equals ( name , "head" , StringComparison . OrdinalIgnoreCase )
376+ || string . Equals ( name , "script" , StringComparison . OrdinalIgnoreCase )
377+ || string . Equals ( name , "style" , StringComparison . OrdinalIgnoreCase ) ;
376378
377- bool isDisplayScriptingText = ( name == "head" || name == "script" || name == "style" ) ;
378-
379379 InternalInnerText ( sb , isDisplayScriptingText , depthLevel ) ;
380380 }
381381 else
@@ -1984,7 +1984,7 @@ public virtual void WriteTo(TextWriter outText, int level = 0)
19841984 if ( _ownerdocument . OptionOutputAsXml )
19851985 {
19861986 var commentNode = ( HtmlCommentNode ) this ;
1987- if ( ! _ownerdocument . BackwardCompatibility && commentNode . Comment . ToLowerInvariant ( ) . StartsWith ( "<!doctype" ) )
1987+ if ( ! _ownerdocument . BackwardCompatibility && commentNode . Comment . StartsWith ( "<!doctype" , StringComparison . OrdinalIgnoreCase ) )
19881988 {
19891989 outText . Write ( commentNode . Comment ) ;
19901990 }
@@ -2623,6 +2623,8 @@ public void AddClass(string name)
26232623 AddClass ( name , false ) ;
26242624 }
26252625
2626+ private static readonly char [ ] spaceSeparator = { ' ' } ;
2627+
26262628 /// <summary>
26272629 /// Adds one or more classes to this node.
26282630 /// </summary>
@@ -2631,26 +2633,26 @@ public void AddClass(string name)
26312633 public void AddClass ( string name , bool throwError )
26322634 {
26332635 var classAttributes = Attributes . AttributesWithName ( "class" ) ;
2636+ var isEmpty = true ;
26342637
2635- if ( ! IsEmpty ( classAttributes ) )
2638+ foreach ( HtmlAttribute att in classAttributes )
26362639 {
2637- foreach ( HtmlAttribute att in classAttributes )
2638- {
2639- // Check class solo, check class in First with other class, check Class no first.
2640- if ( att . Value != null && att . Value . Split ( ' ' ) . ToList ( ) . Any ( x => x . Equals ( name ) ) )
2641- {
2642- if ( throwError )
2643- {
2644- throw new Exception ( HtmlDocument . HtmlExceptionClassExists ) ;
2645- }
2646- }
2647- else
2640+ isEmpty = false ;
2641+ // Check class solo, check class in First with other class, check Class no first.
2642+ if ( att . Value != null && Array . IndexOf ( att . Value . Split ( spaceSeparator ) , name ) != - 1 )
2643+ {
2644+ if ( throwError )
26482645 {
2649- SetAttributeValue ( att . Name , att . Value + " " + name ) ;
2646+ throw new Exception ( HtmlDocument . HtmlExceptionClassExists ) ;
26502647 }
26512648 }
2649+ else
2650+ {
2651+ SetAttributeValue ( att . Name , att . Value + " " + name ) ;
2652+ }
26522653 }
2653- else
2654+
2655+ if ( isEmpty )
26542656 {
26552657 HtmlAttribute attribute = _ownerdocument . CreateAttribute ( "class" , name ) ;
26562658 Attributes . Append ( attribute ) ;
@@ -2718,7 +2720,7 @@ public void RemoveClass(string name, bool throwError)
27182720 {
27192721 Attributes . Remove ( att ) ;
27202722 }
2721- else if ( att . Value != null && att . Value . Split ( ' ' ) . ToList ( ) . Any ( x => x . Equals ( name ) ) )
2723+ else if ( att . Value != null && att . Value . Split ( ' ' ) . Contains ( name ) )
27222724 {
27232725 string [ ] classNames = att . Value . Split ( ' ' ) ;
27242726
0 commit comments