Example #1
0
 public void CopyTo(AttributeList list)
 {
     if (list == null)
     {
         list = new AttributeList();
     }
     this.Reset();
     for (Attribute attribute = this.Next(); attribute != null; attribute = this.Next())
     {
         Attribute a = new Attribute(attribute.name, attribute.val, attribute.ns, attribute.system);
         list.Add(a);
     }
     this.Reset();
     list.Reset();
 }
Example #2
0
 public void CopyTo(AttributeList list)
 {
     if (list == null)
     {
         list = new AttributeList();
     }
     this.Reset();
     for (Attribute attribute = this.Next(); attribute != null; attribute = this.Next())
     {
         Attribute a = new Attribute(attribute.name, attribute.val, attribute.ns, attribute.system);
         list.Add(a);
     }
     this.Reset();
     list.Reset();
 }
Example #3
0
        public Node Parse(XmlNode XMLNode, Types mTypes, EntityManager mEntities, bool recurse, StyleAttributes styleAttributes, bool bParentShift)
        {
            bool hasSelect      = false;
            bool hasSelectRight = false;
            Node result         = null;

            if (!bParentShift)
            {
                xmlTagName   = XMLNode.LocalName;
                namespaceURI = XMLNode.NamespaceURI;
            }

            int numAttrs = 0;

            if ((recurse && (XMLNode.Attributes != null)) && !bParentShift)
            {
                StyleAttributes attributes = ParseMStyle(XMLNode, style_);
                if (attributes != null)
                {
                    if (style_ == null)
                    {
                        style_ = new StyleAttributes();
                    }
                    attributes.CopyTo(style_);
                }

                numAttrs = XMLNode.Attributes.Count;
                if (numAttrs > 0)
                {
                    if (attrs == null)
                    {
                        attrs = new AttributeList();
                    }

                    for (int i = 0; i < numAttrs; i++)
                    {
                        if (XMLNode.Attributes[i].Name == "nugenCursor")
                        {
                            result    = this;
                            hasSelect = true;
                        }
                        else if (XMLNode.Attributes[i].Name == "nugenCursorEnd")
                        {
                            result          = this;
                            result.IsAppend = true;
                            hasSelectRight  = true;
                        }
                        else
                        {
                            attrs.Add(new Attribute(XMLNode.Attributes[i].Name, XMLNode.Attributes[i].Value, XMLNode.Attributes[i].NamespaceURI));
                        }
                    }

                    if (hasSelect)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursor");
                    }
                    if (hasSelectRight)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursorEnd");
                    }
                }
            }

            if ((XMLNode.NodeType == XmlNodeType.Element) && !bParentShift)
            {
                if (type_ == null)
                {
                    type_ = mTypes[xmlTagName];
                }
                if ((hasSelect && (type_.type == ElementType.Mi)) &&
                    (literalText != null))
                {
                    InternalMark = literalText.Length;
                }
            }

            if (recurse && XMLNode.HasChildNodes)
            {
                XmlNodeList list = XMLNode.ChildNodes;
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].NodeType == XmlNodeType.Text)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += list[i].Value;
                            continue;
                        }

                        if (type_.type == ElementType.Mn)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }

                        if (type_.type == ElementType.Mi)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }

                        if (type_.type != ElementType.Mo)
                        {
                            continue;
                        }

                        string entityChar = list[i].Value.Trim();
                        bool   isGlyph    = false;
                        try
                        {
                            Glyph glyph;

                            if (!(((((entityChar != "(") && (entityChar != ")")) && ((entityChar != "[") && (entityChar != "]"))) &&
                                   (((entityChar != "{") && (entityChar != "}")) && ((entityChar != "|") && (entityChar != "||")))) &&
                                  (((entityChar != "+") && (entityChar != "-")) && ((entityChar != "=") && (entityChar != "/")))))
                            {
                                string entityName = "";


                                switch (entityChar)
                                {
                                case "(":
                                {
                                    entityName = "lpar";
                                    break;
                                }

                                case ")":
                                {
                                    entityName = "rpar";
                                    break;
                                }

                                case "[":
                                {
                                    entityName = "lbrack";
                                    break;
                                }

                                case "]":
                                {
                                    entityName = "rbrack";
                                    break;
                                }

                                case "{":
                                {
                                    entityName = "lbrace";
                                    break;
                                }

                                case "}":
                                {
                                    entityName = "rbrace";
                                    break;
                                }

                                case "|":
                                {
                                    entityName = "verbar";
                                    break;
                                }

                                case "||":
                                {
                                    entityName = "Verbar";
                                    break;
                                }

                                case "+":
                                {
                                    entityName = "plus";
                                    break;
                                }

                                case "-":
                                {
                                    entityName = "minus";
                                    break;
                                }

                                case "=":
                                {
                                    entityName = "equals";
                                    break;
                                }

                                case "/":
                                {
                                    entityName = "sol";
                                    break;
                                }
                                }

                                glyph = mEntities.ByName(entityName);
                                if (glyph != null)
                                {
                                    Node glyphNode = new Node();
                                    glyphNode.type_       = mTypes["entity"];
                                    glyphNode.literalText = "" + glyph.CharValue;
                                    glyphNode.fontFamily  = glyph.FontFamily;
                                    glyphNode.glyph       = glyph;
                                    glyphNode.xmlTagName  = glyph.Name;
                                    AdoptChild(glyphNode);

                                    isGlyph = true;
                                }
                            }
                        }
                        catch
                        {
                        }

                        if (!isGlyph)
                        {
                            literalText += entityChar;
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Whitespace)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += " ";
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Element)
                    {
                        if ((list[i].NamespaceURI == "http://www.w3.org/1998/Math/MathML") && (list[i].LocalName == "mstyle"))
                        {
                            Node mstyl = ParseMstyle(list[i], mTypes, mEntities, recurse, styleAttributes);
                            if (mstyl != null)
                            {
                                result = mstyl;
                            }
                        }
                        else
                        {
                            Node n = new Node(XMLNode.Name, styleAttributes);
                            n.type_ = mTypes[list[i].LocalName];

                            if (AdoptChild(n))
                            {
                                Node sn = n.Parse(list[i], mTypes, mEntities, recurse, styleAttributes, false);
                                if (sn != null)
                                {
                                    result = sn;
                                }
                            }
                        }

                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.EntityReference)
                    {
                        Node n = new Node();
                        n.type_ = mTypes["entity"];
                        if ((type_.type == ElementType.Mtext) ||
                            (type_.type == ElementType.Ms))
                        {
                            Glyph glyph = mEntities.ByName(list[i].LocalName);
                            if (glyph != null)
                            {
                                char c = Convert.ToChar(Convert.ToUInt32(glyph.Code, 0x10));
                                if (char.IsWhiteSpace(c) || char.IsControl(c))
                                {
                                    literalText = literalText + " ";
                                }
                                else
                                {
                                    literalText = literalText + c;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                Glyph glyph = mEntities.ByName(list[i].LocalName);
                                if (glyph != null)
                                {
                                    n.literalText = "";
                                    n.literalText = n.literalText + glyph.CharValue;
                                    n.fontFamily  = glyph.FontFamily;
                                    n.glyph       = glyph;
                                    n.xmlTagName  = list[i].LocalName;
                                }
                                else
                                {
                                    n.literalText = "?";
                                    n.xmlTagName  = list[i].LocalName;
                                }
                                AdoptChild(n);
                            }
                            catch
                            {
                                n.literalText = "?";
                                n.xmlTagName  = list[i].LocalName;
                                AdoptChild(n);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Example #4
0
        private AttributeList ParseAttributes(Stream stream)
        {
            var attributes = new AttributeList(_host);

            var open = stream.Next();
            Token token = null;

            //expecting identifier
            while (stream.Peek() != null)
            {
                token = stream.Peek();
                if (token == null)
                {
                    break;
                }

                switch (token.Type)
                {
                    case TokenType.Identifier:
                        attributes.Add(ParseAttribute(stream));
                        break;
                    case TokenType.CloseBracket:
                        //consume close bracket
                        stream.NextNoReturn();
                        goto doneWithAttribute;
                    default:
                        //invalid token
                        throw new ParserException(token);
                }
            }

            doneWithAttribute:
            if (attributes.Count == 0)
            {
                //must be empty attribute list
                throw new ParserException(token);
            }

            //do reduction here
            return attributes;
        }
Example #5
0
        public Node Parse(XmlNode XMLNode, Types mTypes, EntityManager mEntities, bool recurse, StyleAttributes styleAttributes, bool bParentShift)
        {
            bool hasSelect = false;
            bool hasSelectRight = false;
            Node result = null;
            if (!bParentShift)
            {
                xmlTagName = XMLNode.LocalName;
                namespaceURI = XMLNode.NamespaceURI;
            }
            
            int numAttrs = 0;
            
            if ((recurse && (XMLNode.Attributes != null)) && !bParentShift)
            {
                StyleAttributes attributes = ParseMStyle(XMLNode, style_);
                if (attributes != null)
                {
                    if (style_ == null)
                    {
                        style_ = new StyleAttributes();
                    }
                    attributes.CopyTo(style_);
                }
            
                numAttrs = XMLNode.Attributes.Count;
                if (numAttrs > 0)
                {
                    if (attrs == null)
                    {
                        attrs = new AttributeList();
                    }

                    for (int i = 0; i < numAttrs; i++)
                    {
                        
                        if (XMLNode.Attributes[i].Name == "nugenCursor")
                        {
                            result = this;
                            hasSelect = true;
                        }
                        else if (XMLNode.Attributes[i].Name == "nugenCursorEnd")
                        {
                            result = this;
                            result.IsAppend = true;
                            hasSelectRight = true;
                        }
                        else
                        {
                            attrs.Add(new Attribute(XMLNode.Attributes[i].Name, XMLNode.Attributes[i].Value, XMLNode.Attributes[i].NamespaceURI));
                        }
                    }

                    if (hasSelect)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursor");
                    }
                    if (hasSelectRight)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursorEnd");
                    }
                }
            }

            if ((XMLNode.NodeType == XmlNodeType.Element) && !bParentShift)
            {
                if (type_ == null)
                {
                    type_ = mTypes[xmlTagName];
                }
                if ((hasSelect && (type_.type == ElementType.Mi)) &&
                    (literalText != null))
                {
                    InternalMark = literalText.Length;
                }
            }

            if (recurse && XMLNode.HasChildNodes)
            {
                XmlNodeList list = XMLNode.ChildNodes;
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].NodeType == XmlNodeType.Text)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += list[i].Value;
                            continue;
                        }
                        
                        if (type_.type == ElementType.Mn)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }
                        
                        if (type_.type == ElementType.Mi)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }

                        if (type_.type != ElementType.Mo)
                        {
                            continue;
                        }

                        string entityChar = list[i].Value.Trim();
                        bool isGlyph = false;
                        try
                        {
                            Glyph glyph;

                            if (! (((((entityChar != "(") && (entityChar != ")")) && ((entityChar != "[") && (entityChar != "]"))) &&
                                    (((entityChar != "{") && (entityChar != "}")) && ((entityChar != "|") && (entityChar != "||")))) &&
                                   (((entityChar != "+") && (entityChar != "-")) && ((entityChar != "=") && (entityChar != "/")))))
                            {
                                string entityName = "";


                                switch (entityChar)
                                {
                                    case "(":
                                    {
                                        entityName = "lpar";
                                        break;
                                    }
                                    case ")":
                                    {
                                        entityName = "rpar";
                                        break;
                                    }
                                    case "[":
                                    {
                                        entityName = "lbrack";
                                        break;
                                    }
                                    case "]":
                                    {
                                        entityName = "rbrack";
                                        break;
                                    }
                                    case "{":
                                    {
                                        entityName = "lbrace";
                                        break;
                                    }
                                    case "}":
                                    {
                                        entityName = "rbrace";
                                        break;
                                    }
                                    case "|":
                                    {
                                        entityName = "verbar";
                                        break;
                                    }
                                    case "||":
                                    {
                                        entityName = "Verbar";
                                        break;
                                    }
                                    case "+":
                                    {
                                        entityName = "plus";
                                        break;
                                    }
                                    case "-":
                                    {
                                        entityName = "minus";
                                        break;
                                    }
                                    case "=":
                                    {
                                        entityName = "equals";
                                        break;
                                    }
                                    case "/":
                                    {
                                        entityName = "sol";
                                        break;
                                    }
                                }

                                glyph = mEntities.ByName(entityName);
                                if (glyph != null)
                                {
                                    Node glyphNode = new Node();
                                    glyphNode.type_ = mTypes["entity"];
                                    glyphNode.literalText = "" + glyph.CharValue;
                                    glyphNode.fontFamily = glyph.FontFamily;
                                    glyphNode.glyph = glyph;
                                    glyphNode.xmlTagName = glyph.Name;
                                    AdoptChild(glyphNode);
                                    
                                    isGlyph = true;
                                }
                            }
                        }
                        catch
                        {
                        }

                        if (!isGlyph)
                        {
                            literalText += entityChar;
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Whitespace)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += " ";
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Element)
                    {
                        if ((list[i].NamespaceURI == "http://www.w3.org/1998/Math/MathML") && (list[i].LocalName == "mstyle"))
                        {
                            Node mstyl = ParseMstyle(list[i], mTypes, mEntities, recurse, styleAttributes);
                            if (mstyl != null)
                            {
                                result = mstyl;
                            }
                        }
                        else
                        {
                            Node n = new Node(XMLNode.Name, styleAttributes);
                            n.type_ = mTypes[list[i].LocalName];

                            if (AdoptChild(n))
                            {
                                Node sn = n.Parse(list[i], mTypes,  mEntities, recurse, styleAttributes, false);
                                if (sn != null)
                                {
                                    result = sn;
                                }
                            }
                        }

                        continue;
                    }
                
                    if (list[i].NodeType == XmlNodeType.EntityReference)
                    {
                        Node n = new Node();
                        n.type_ = mTypes["entity"];
                        if ((type_.type == ElementType.Mtext) ||
                            (type_.type == ElementType.Ms))
                        {
                            Glyph glyph = mEntities.ByName(list[i].LocalName);
                            if (glyph != null)
                            {
                                char c = Convert.ToChar(Convert.ToUInt32(glyph.Code, 0x10));
                                if (char.IsWhiteSpace(c) || char.IsControl(c))
                                {
                                    literalText = literalText + " ";
                                }
                                else
                                {
                                    literalText = literalText + c;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                Glyph glyph = mEntities.ByName(list[i].LocalName);
                                if (glyph != null)
                                {
                                    n.literalText = "";
                                    n.literalText = n.literalText + glyph.CharValue;
                                    n.fontFamily = glyph.FontFamily;
                                    n.glyph = glyph;
                                    n.xmlTagName = list[i].LocalName;
                                }
                                else
                                {
                                    n.literalText = "?";
                                    n.xmlTagName = list[i].LocalName;
                                }
                                AdoptChild(n);
                            }
                            catch
                            {
                                n.literalText = "?";
                                n.xmlTagName = list[i].LocalName;
                                AdoptChild(n);
                            }
                        }
                    }
                }
            }
            return result;
        }