Ejemplo n.º 1
0
 public static string GetInternalText(TextSource textsource)
 {
     return(new string(TextSnapshot.UnsafeGetInternalBuffer(textsource._actualSnapshot)));
 }
Ejemplo n.º 2
0
        public override void Analyze(TextSnapshot textSnapshot)
        {
#if DEBUG
            dbug_OnStartAnalyze();
#endif

            this.textSnapshot = textSnapshot;
            char[] sourceBuffer  = TextSnapshot.UnsafeGetInternalBuffer(textSnapshot);
            int    lim           = sourceBuffer.Length;
            char   strEscapeChar = '"';
            int    currentState  = 0;
            //-----------------------------

            for (int i = 0; i < lim; i++)
            {
                char c = sourceBuffer[i];
#if DEBUG
                dbug_currentLineCharIndex++;
                dbugReportChar(c, currentState);
#endif
                switch (currentState)
                {
                default:
                {
                    //???
                }
                break;

                case 0:      //from content mode
                {
                    if (c == '<')
                    {
                        //flush existing content
                        //switch to content  tag mode
                        FlushExisingBuffer(i, XmlLexerEvent.FromContentPart);
                        currentState = 1;
                        //not need whitespace in this mode
                    }
                    else
                    {
                        //in content mode
                        AppendBuffer(c, i);
                    }
                }
                break;

                case 1:
                {
                    //after open angle
                    switch (c)
                    {
                    case '!':
                    {
                        currentState = 11;                 //<!
                    }
                    break;

                    case '?':
                    {
                        //process instruction
                        currentState = 8;
                    }
                    break;

                    case ':':
                    {
                        //shold not occurs
                        currentState = 4;
                    }
                    break;

                    case '/':
                    {
                        //close tag
                        RaiseStateChanged(XmlLexerEvent.VisitOpenSlashAngle, i, 1);
                        currentState = 5;                //collect node name
                    }
                    break;

                    default:
                    {
                        currentState = 5;
                        //clear prev buffer
                        //then start collect node name

                        AppendBuffer(c, i);
                    }
                    break;
                    }
                }
                break;

                case 2:
                {
                    //inside comment node
                    if (c == '-')
                    {
                        if (i < lim - 2)
                        {
                            if (sourceBuffer[i + 1] == '-' && sourceBuffer[i + 2] == '>')
                            {
                                //end comment node
                                FlushExisingBuffer(i, XmlLexerEvent.CommentContent);
                                i           += 2;
                                currentState = 0;
                                continue;
                            }
                        }
                    }
                    //skip all comment  content ?
                    AppendBuffer(c, i);
                }
                break;

                case 5:
                {
                    //inside open angle
                    //name collecting
                    //terminate with...
                    switch (c)
                    {
                    case '/':
                    {
                        currentState = 7;
                    }
                    break;

                    case '>':
                    {
                        FlushExisingBuffer(i, XmlLexerEvent.NodeNameOrAttribute);
                        RaiseStateChanged(XmlLexerEvent.VisitCloseAngle, i, 1);
                        //flush
                        currentState = 0;
                        //goto content mode
                    }
                    break;

                    case ':':
                    {
                        //flush node name
                        FlushExisingBuffer(i, XmlLexerEvent.NamePrefix);
                        //start new node name
                    }
                    break;

                    case ' ':
                    {
                        //flush node name
                        FlushExisingBuffer(i, XmlLexerEvent.NodeNameOrAttribute);
                    }
                    break;

                    case '=':
                    {
                        //flush name
                        FlushExisingBuffer(i, XmlLexerEvent.Attribute);
                        RaiseStateChanged(XmlLexerEvent.VisitAttrAssign, i, 1);
                        //start collect value of attr
                    }
                    break;

                    case '"':
                    {
                        //start string escap with "
                        currentState  = 6;
                        strEscapeChar = '"';
                    }
                    break;

                    case '\'':
                    {
                        //start string escap with '
                        currentState  = 6;
                        strEscapeChar = '\'';
                    }
                    break;

                    default:
                    {
                        //else collect
                        //flush nodename

                        if (char.IsWhiteSpace(c))
                        {
                            FlushExisingBuffer(i, XmlLexerEvent.NodeNameOrAttribute);
                        }
                        else
                        {
                            AppendBuffer(c, i);
                        }
                    }
                    break;
                    }
                }
                break;

                case 6:
                {
                    //collect string
                    if (c == strEscapeChar)
                    {
                        //stop string escape
                        //flush
                        FlushExisingBuffer(i, XmlLexerEvent.AttributeValueAsLiteralString);
                        currentState = 5;
                    }
                    else
                    {
                        AppendBuffer(c, i);
                    }
                }
                break;

                case 7:
                {
                    //after /   //must be >
                    if (c == '>')
                    {
                        FlushExisingBuffer(i, XmlLexerEvent.NodeNameOrAttribute);
                        RaiseStateChanged(XmlLexerEvent.VisitCloseSlashAngle, i, 1);
                        currentState = 0;
                    }
                    else
                    {
                        //error ?
                    }
                }
                break;

                case 8:
                {
                    //enter processing instruction
                    if (c == '?')
                    {
                        //exit
                        currentState = 9;
                    }
                }
                break;

                case 9:
                {
                    if (c == '>')
                    {
                        //flush xml processing instruction
                        FlushExisingBuffer(i, XmlLexerEvent.ProcessInstructionContent);
                        currentState = 0;         //back to content mode
                    }
                }
                break;

                case 10:
                {
                    //unknown tag
                    //exit from this tag when found >
                    if (c == '>')
                    {
                        currentState = 0;
                    }
                }
                break;

                case 11:
                {
                    //open_angle, exlcimation
                    switch (c)
                    {
                    case '-':
                    {
                        //looking for next char
                        if (i < lim)
                        {
                            if (sourceBuffer[i + 1] == '-')
                            {
                                i++;                //consume
                                currentState = 2;
                                continue;
                            }
                            else
                            {
                                //unknown tag?
                                currentState = 10;
                            }
                        }
                    }
                    break;

                    case '[':
                    {
                        // <![
                        //
                        currentState = 10;                //not implement,just skip
                    }
                    break;

                    default:
                    {
                        //doc type?
                        if (char.IsLetter(sourceBuffer[i + 1]))
                        {
                            RaiseStateChanged(XmlLexerEvent.VisitOpenAngleExclimation, i, 2);
                            AppendBuffer(c, i);
                            currentState = 5;
                        }
                        else
                        {
                            currentState = 10;                //not implement, just skip
                        }
                    }
                    break;
                    }
                }
                break;
                }
            }

#if DEBUG
            dbug_OnFinishAnalyze();
#endif
        }
Ejemplo n.º 3
0
 public static char[] DecodeHtml(TextSnapshot source, int startIndex, int decLength)
 {
     return(DecodeHtml(TextSnapshot.UnsafeGetInternalBuffer(source), startIndex, decLength));
 }