Ejemplo n.º 1
0
    public static string GetText(bool trim = false)
    {
        if (lastTagEnd == tagPos)
        {
            return(string.Empty);
        }
        else if (trim)
        {
            int i = lastTagEnd;
            for (; i < tagPos; i++)
            {
                char c = source[i];
                if (!char.IsWhiteSpace(c))
                {
                    break;
                }
            }

            if (i == tagPos)
            {
                return(string.Empty);
            }
            else
            {
                return(XMLUtils.DecodeString(source.Substring(i, tagPos - i).TrimEnd()));
            }
        }
        else
        {
            return(XMLUtils.DecodeString(source.Substring(lastTagEnd, tagPos - lastTagEnd)));
        }
    }
Ejemplo n.º 2
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;
                }
            }
        }
    }