[Adapdev-commits] Adapdev/src/Adapdev.Web/Html HtmlParser.cs,1.4,1.5
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-26 08:51:37
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Web/Html In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26163/src/Adapdev.Web/Html Modified Files: HtmlParser.cs Log Message: Index: HtmlParser.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Web/Html/HtmlParser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HtmlParser.cs 16 Nov 2005 07:02:00 -0000 1.4 --- HtmlParser.cs 26 Nov 2005 08:51:25 -0000 1.5 *************** *** 179,190 **** if( "SCRIPT".Equals( element.Name.ToUpper() ) && ! element.IsClosed ) { ! bool ignoreSingleQuotes = true; ! /* ! * TODO: Is VBScript the only fella that uses single quotes in a manner other than to quote things...? ! if( element.Attributes[ "VBSCRIPT" ] == null ) { ignoreSingleQuotes = true; } - */ String script = ""; inChar = ExtractScript( reader , ref script , inChar , ignoreSingleQuotes ); --- 179,188 ---- if( "SCRIPT".Equals( element.Name.ToUpper() ) && ! element.IsClosed ) { ! bool ignoreSingleQuotes = false; ! HtmlAttribute langAttr = element.Attributes[ "lang" ]; ! if( langAttr != null && langAttr.Value != null && "vbscript".Equals( langAttr.Value.ToLower() ) ) { ignoreSingleQuotes = true; } String script = ""; inChar = ExtractScript( reader , ref script , inChar , ignoreSingleQuotes ); *************** *** 199,202 **** --- 197,207 ---- OnElementClose( document , new HtmlElementClose( element.Name ) ); } + else if( "TEXTAREA".Equals( element.Name.ToUpper() ) && ! element.IsClosed ) + { + String textAreaContents = ""; + inChar = ExtractTextArea( reader , ref textAreaContents , inChar ); + OnText( document , new HtmlText( textAreaContents ) ); + OnElementClose( document , new HtmlElementClose( element.Name ) ); + } } else if( node != null ) *************** *** 417,429 **** private int ExtractScript(TextReader reader,ref string text,int inChar,bool ignoreSingleQuotes) { ! return ExtractUntil( reader , "</SCRIPT>" , ref text , inChar , "Script not closed" , true , ignoreSingleQuotes ); } private int ExtractStyle(TextReader reader,ref string text,int inChar) { ! return ExtractUntil( reader , "</STYLE>" , ref text , inChar , "Style not closed" , true , false ); } ! private int ExtractUntil(TextReader reader,String terminatorText,ref string text,int inChar,string failMessage,bool respectQuotationMarks,bool ignoreSingleQuotes) { StringBuilder comment = new StringBuilder(); --- 422,476 ---- private int ExtractScript(TextReader reader,ref string text,int inChar,bool ignoreSingleQuotes) { ! return ExtractUntil( reader , "</SCRIPT>" , ref text , inChar , "Script not closed" , true , ignoreSingleQuotes, false, true ); } private int ExtractStyle(TextReader reader,ref string text,int inChar) { ! return ExtractUntil( reader , "</STYLE>" , ref text , inChar , "Style not closed" , true , false , true, false); } ! private int ExtractTextArea(TextReader reader,ref string text,int inChar) ! { ! return ExtractBasicUntil( reader , "</TEXTAREA>" , ref text , inChar , "TextArea not closed" ); ! } ! ! private int ExtractBasicUntil(TextReader reader,String terminatorText,ref string text,int inChar,string failMessage) ! { ! StringBuilder comment = new StringBuilder(); ! char[] terms = terminatorText.ToUpper().ToCharArray(); ! char[] cTemp = new char [ terms.Length ]; ! cTemp[ cTemp.Length - 1 ] = (char) inChar; ! while( inChar != END_OF_FILE ) ! { ! int i = 0; ! for( i = 0 ; i < terms.Length ; i++ ) ! { ! if( terms[i] != char.ToUpper( cTemp[i] ) ) break; ! } ! if( i == terms.Length ) break; ! for( i = 0 ; i < cTemp.Length - 1 ; i++ ) ! { ! cTemp[ i ] = cTemp[ i + 1]; ! } ! cTemp[ cTemp.Length - 1 ] = (char) inChar; ! comment.Append( (char) inChar ); ! inChar = reader.Read(); ! } ! text = comment.ToString(); ! if( text.Length >= terminatorText.Length && text.Substring( text.Length - terminatorText.Length ).ToUpper().Equals( terminatorText.ToUpper() ) ) ! { ! text = text.Substring( 0 , text.Length - terminatorText.Length ); ! } ! else ! { ! if( ! IgnoreErrors ) ! { ! throw new HtmlParserException( failMessage , mLineNumber ); ! } ! } ! return inChar; ! } ! ! private int ExtractUntil(TextReader reader,String terminatorText,ref string text,int inChar,string failMessage,bool respectQuotationMarks,bool ignoreSingleQuotes, bool hasCssCommments, bool hasJsComments) { StringBuilder comment = new StringBuilder(); *************** *** 433,436 **** --- 480,487 ---- bool inDoubleQuotes = false; bool inSingleQuotes = false; + bool inComment = false; + int c0 = 0; + int c1 = 0; + int c2 = inChar; if( inChar == '\"' ) inDoubleQuotes = true; if( inChar == '\'' ) inSingleQuotes = true; *************** *** 464,471 **** cTemp[ cTemp.Length - 1 ] = (char) inChar; int oldChar = inChar; inChar = reader.Read(); ! if( inChar == '\"' && ! inSingleQuotes && ! ( oldChar == '\\' ) ) inDoubleQuotes = !inDoubleQuotes; ! if( inChar == '\'' && ! inDoubleQuotes && ! ( oldChar == '\\' ) ) inSingleQuotes = !inSingleQuotes; ! if( inChar == '\n' ) mLineNumber++; } text = comment.ToString(); --- 515,554 ---- cTemp[ cTemp.Length - 1 ] = (char) inChar; int oldChar = inChar; + c0 = c1; + c1 = c2; + c2 = inChar; inChar = reader.Read(); ! ! if (!inComment && !inSingleQuotes && !inDoubleQuotes && (hasCssCommments || hasJsComments) && ('/' == (char) c2) && ('*' == (char) inChar)) ! { ! string s = ""; ! inChar = ExtractJScriptComment(reader, ref s, inChar); ! comment.Append(s); ! comment.Append("*/"); ! c0 = 0; ! c1 = 0; ! c2 = 0; ! } ! if (!inComment && !inSingleQuotes && !inDoubleQuotes && (hasCssCommments || hasJsComments) && ('<' == (char) c0) && ('!' == (char) c1) && ('-' == (char) c2) && ('-' == (char) inChar)) ! { ! string s = ""; ! inChar = ExtractComment(reader, ref s, inChar); ! comment.Append(s); ! comment.Append("-->"); ! c0 = 0; ! c1 = 0; ! c2 = 0; ! } ! if (!inComment && !inSingleQuotes && !inDoubleQuotes && hasJsComments && ('/' == (char) c2) && ('/' == (char) inChar)) ! { ! inComment = true; ! } ! if( inChar == '\"' && ! inSingleQuotes && !inComment && ! ( oldChar == '\\' ) ) inDoubleQuotes = !inDoubleQuotes; ! if( inChar == '\'' && ! inDoubleQuotes && !inComment && ! ( oldChar == '\\' ) ) inSingleQuotes = !inSingleQuotes; ! if( inChar == '\n' ) ! { ! mLineNumber++; ! inComment = false; ! } } text = comment.ToString(); *************** *** 523,526 **** --- 606,648 ---- } + // Catalyst function + private int ExtractJScriptComment(TextReader reader,ref String text,int inChar) + { + StringBuilder comment = new StringBuilder(); + int c1=0; + while( inChar != END_OF_FILE ) + { + if( c1 == '*' && inChar == '/' ) + { + break; + } + comment.Append( (char) inChar ); + c1 = inChar; + inChar = reader.Read(); + if( inChar == '\n' ) mLineNumber++; + } + if( comment.Length > 1 ) + { + text = comment.ToString().Substring( 0 , comment.Length - 2 ); + } + else + { + text = ""; + } + if( inChar == '/' ) + { + inChar = reader.Read(); + if( inChar == '\n' ) mLineNumber++; + } + else + { + if( ! IgnoreErrors ) + { + throw new HtmlParserException( "Comment not closed" , mLineNumber ); + } + } + return inChar; + } + private int ExtractSGMLComment(TextReader reader,ref String text,int inChar) { |