static public int constructor(IntPtr l)
 {
     try {
         FairyGUI.Utils.XMLUtils o;
         o = new FairyGUI.Utils.XMLUtils();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 2
0
        void ToXMLString(StringBuilder sb, int tabs)
        {
            if (tabs > 0)
            {
                sb.Append(' ', tabs * 2);
            }

            if (name == "!")
            {
                sb.Append("<!--");
                if (text != null)
                {
                    int c = sb.Length;
                    sb.Append(text);
                    XMLUtils.EncodeString(sb, c);
                }
                sb.Append("-->");
                return;
            }

            sb.Append('<').Append(name);
            if (_attributes != null)
            {
                foreach (KeyValuePair <string, string> kv in _attributes)
                {
                    sb.Append(' ');
                    sb.Append(kv.Key).Append('=').Append('\"');
                    int c = sb.Length;
                    sb.Append(kv.Value);
                    XMLUtils.EncodeString(sb, c, true);
                    sb.Append("\"");
                }
            }

            int numChildren = _children != null ? _children.Count : 0;

            if (string.IsNullOrEmpty(text) && numChildren == 0)
            {
                sb.Append("/>");
            }
            else
            {
                sb.Append('>');

                if (!string.IsNullOrEmpty(text))
                {
                    int c = sb.Length;
                    sb.Append(text);
                    XMLUtils.EncodeString(sb, c);
                }

                if (numChildren > 0)
                {
                    sb.Append('\n');
                    int ctabs = tabs + 1;
                    for (int i = 0; i < numChildren; i++)
                    {
                        _children[i].ToXMLString(sb, ctabs);
                        sb.Append('\n');
                    }

                    if (tabs > 0)
                    {
                        sb.Append(' ', tabs * 2);
                    }
                }

                sb.Append("</").Append(name).Append(">");
            }
        }
Ejemplo n.º 3
0
        static void ParseAttributes(IDictionary attrs)
        {
            string attrName;
            int    valueStart;
            int    valueEnd;
            bool   waitValue = false;
            int    quoted;

            buffer.Length = 0;
            int i       = tagPos;
            int attrEnd = tagPos + tagLength;

            if (i < attrEnd && source[i] == '<')
            {
                for (; i < attrEnd; i++)
                {
                    char c = source[i];
                    if (Char.IsWhiteSpace(c) || c == '>' || c == '/')
                    {
                        break;
                    }
                }
            }

            for (; i < attrEnd; i++)
            {
                char c = source[i];
                if (c == '=')
                {
                    valueStart = -1;
                    valueEnd   = -1;
                    quoted     = 0;
                    for (int j = i + 1; j < attrEnd; j++)
                    {
                        char c2 = source[j];
                        if (Char.IsWhiteSpace(c2))
                        {
                            if (valueStart != -1 && quoted == 0)
                            {
                                valueEnd = j - 1;
                                break;
                            }
                        }
                        else if (c2 == '>')
                        {
                            if (quoted == 0)
                            {
                                valueEnd = j - 1;
                                break;
                            }
                        }
                        else if (c2 == '"')
                        {
                            if (valueStart != -1)
                            {
                                if (quoted != 1)
                                {
                                    valueEnd = j - 1;
                                    break;
                                }
                            }
                            else
                            {
                                quoted     = 2;
                                valueStart = j + 1;
                            }
                        }
                        else if (c2 == '\'')
                        {
                            if (valueStart != -1)
                            {
                                if (quoted != 2)
                                {
                                    valueEnd = j - 1;
                                    break;
                                }
                            }
                            else
                            {
                                quoted     = 1;
                                valueStart = j + 1;
                            }
                        }
                        else if (valueStart == -1)
                        {
                            valueStart = j;
                        }
                    }

                    if (valueStart != -1 && valueEnd != -1)
                    {
                        attrName = buffer.ToString();
                        if (lowerCaseName)
                        {
                            attrName = attrName.ToLower();
                        }
                        buffer.Length   = 0;
                        attrs[attrName] = XMLUtils.DecodeString(source.Substring(valueStart, valueEnd - valueStart + 1));
                        i = valueEnd + 1;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (!Char.IsWhiteSpace(c))
                {
                    if (waitValue || c == '/' || c == '>')
                    {
                        if (buffer.Length > 0)
                        {
                            attrName = buffer.ToString();
                            if (lowerCaseName)
                            {
                                attrName = attrName.ToLower();
                            }
                            attrs[attrName] = string.Empty;
                            buffer.Length   = 0;
                        }

                        waitValue = false;
                    }

                    if (c != '/' && c != '>')
                    {
                        buffer.Append(c);
                    }
                }
                else
                {
                    if (buffer.Length > 0)
                    {
                        waitValue = true;
                    }
                }
            }
        }