예제 #1
0
        private void ParseLinkTags(ref string strText)
        {
            if (string.IsNullOrEmpty(strText))
            {
                _ResetLinkTags(0);
                return;
            }
            mUnderlineTagInfos.Clear();
            LinkCache linkCache = null;

            if (m_SupportCache)
            {
                linkCache = CacheManager.Instance.GetLinkCache(strText.GetHashCode());
                if (linkCache != null)
                {
                    for (int i = 0; i < linkCache.GetParams().Count; ++i)
                    {
                        LinkCache.CacheLinkTag tag = linkCache.GetParams()[i];
                        LinkTag selftag            = _GetLinkTag(i);
                        selftag.SetStartIndex(tag.StartIndex);
                        selftag.SetEndIndex(tag.EndIndex);
                        mUnderlineTagInfos.Add(selftag);

                        if (tag.paramDic != null)
                        {
                            var iter = tag.paramDic.GetEnumerator();
                            while (iter.MoveNext())
                            {
                                selftag.CheckSetValue(iter.Current.Key, iter.Current.Value);
                            }
                            iter.Dispose();
                        }
                    }

                    strText = linkCache.GetResultString();
                    _ResetSpriteTags(linkCache.GetParams().Count);
                    return;
                }
            }

            int linkCount = 0;

            mTextBuilder.Length = 0;
            XMLIterator.Begin(strText, false);
            string textBlock = string.Empty;

            mTagPos.Clear();
            while (XMLIterator.NextTag())
            {
                mParses.Clear();
                if (XMLIterator.tagName == mLinkTag)
                {
                    textBlock = XMLIterator.GetText(false);
                    if (!mTagPos.ContainsKey(mLinkTag))
                    {
                        XMLIterator.tagOffset += XMLIterator.tagOffset;
                        mTagPos[mLinkTag]      = (XMLIterator.parsePos - XMLIterator.tagOffset) * 4;
                        LinkTag tag = _GetLinkTag(lineCount);
                        mUnderlineTagInfos.Add(tag);
                        tag.SetStartIndex(mTagPos[mLinkTag]);
                        XMLIterator.GetAttributes(mParses);
                        foreach (var val in mParses)
                        {
                            tag.CheckSetValue(val.Key, val.Value);
                        }
                    }
                    else
                    {
                        LinkTag tag = _GetLinkTag(lineCount);
                        XMLIterator.tagOffset += XMLIterator.tagLength;
                        tag.SetEndIndex((XMLIterator.parsePos - XMLIterator.tagOffset) * 4);
                        mTagPos.Remove(mLinkTag);

                        if (m_SupportCache)
                        {
                            linkCache = CacheManager.Instance.AddLinkCache(strText.GetHashCode());
                            LinkCache.CacheLinkTag cacheTag = new LinkCache.CacheLinkTag();
                            cacheTag.StartIndex = tag.GetStartIndex();
                            cacheTag.EndIndex   = tag.GetEndIndex();

                            if (cacheTag.paramDic == null)
                            {
                                cacheTag.paramDic = new Dictionary <string, string>();
                            }
                            var iter = tag.GetParams().GetEnumerator();
                            while (iter.MoveNext())
                            {
                                cacheTag.paramDic.Add(iter.Current.Key, iter.Current.Value);
                            }
                            linkCache.AddParams(cacheTag);
                        }
                        ++lineCount;
                    }
                }
                else
                {
                    textBlock = XMLIterator.GetText(false);
                    mTextBuilder.Append(textBlock);
                    mTextBuilder.Append(XMLIterator.GetTagSource());
                }
            }
            textBlock = XMLIterator.GetText(false);
            mTextBuilder.Append(textBlock);
            string result = mTextBuilder.ToString();

            if (m_SupportCache)
            {
                linkCache = CacheManager.Instance.GetLinkCache(strText.GetHashCode());
                if (linkCache != null)
                {
                    linkCache.SetResultString(result);
                }
            }
            strText = result;

            _ResetLinkTags(linkCount);
        }
예제 #2
0
        private void ParseSpriteTags(string strText)
        {
            if (string.IsNullOrEmpty(strText) || -1 == strText.IndexOf("quad"))
            {
                _ResetSpriteTags(0);
                return;
            }
            ImageCache imageCache = null;

            if (m_SupportCache)
            {
                imageCache = CacheManager.Instance.GetImgCache(strText.GetHashCode());
                if (imageCache != null)
                {
                    List <ImageCache.CacheImageTag> imageCacheParms = imageCache.GetParams();
                    for (int i = 0; i < imageCacheParms.Count; ++i)
                    {
                        SpriteTag tag = _GetSpriteTag(1);
                        if (imageCacheParms[i].paramDic != null)
                        {
                            var iter = imageCacheParms[i].paramDic.GetEnumerator();
                            while (iter.MoveNext())
                            {
                                tag.CheckSetValue(imageCacheParms[i].position, iter.Current.Key, iter.Current.Value);
                            }
                            iter.Dispose();
                        }
                    }
                    _ResetSpriteTags(imageCacheParms.Count);
                }
            }

            int imgCount = 0;

            XMLIterator.Begin(strText, false);
            string textBlock = string.Empty;

            mTagPos.Clear();
            int tagLength       = 0;
            int mImgTagCount    = 0;
            int line            = 0;
            int richXMLTagCount = 0;

            while (XMLIterator.NextTag())
            {
                mParses.Clear();
                if (XMLIterator.tagName == mImgTag)
                {
                    {
                        line = Regex.Matches(strText.Substring(0, XMLIterator.parsePos), "\n").Count;

                        mTagPos[mImgTag] = XMLIterator.parsePos + XMLIterator.tagLength;
                        XMLIterator.GetAttributes(mParses);
                        SpriteTag tag = _GetSpriteTag(imgCount);
                        tagLength += XMLIterator.tagLength;
                        foreach (var val in mParses)
                        {
                            tag.CheckSetValue(XMLIterator.parsePos + mImgTagCount - tagLength - line - richXMLTagCount, val.Key, val.Value);
                        }
                        mImgTagCount++;
                    }

                    if (m_SupportCache)
                    {
                        SpriteTag tag = _GetSpriteTag(imgCount);
                        imageCache = CacheManager.Instance.AddImgCache(strText.GetHashCode());
                        ImageCache.CacheImageTag cacheTag = new ImageCache.CacheImageTag();
                        if (cacheTag.paramDic == null)
                        {
                            cacheTag.paramDic = new Dictionary <string, string>();
                        }
                        cacheTag.position           = tag.GetVertexStartIndex();
                        cacheTag.paramDic["name"]   = tag.GetName();
                        cacheTag.paramDic["src"]    = tag.GetSrc();
                        cacheTag.paramDic["width"]  = tag.GetWidth();
                        cacheTag.paramDic["height"] = tag.GetHeight();
                        if (m_SupportDynamicChart)
                        {
                            cacheTag.paramDic["start"] = tag.GetStartFrame().ToString();
                            cacheTag.paramDic["end"]   = tag.GetEndFrame().ToString();
                        }

                        imageCache.AddParams(cacheTag);
                    }
                    ++imgCount;
                }
                else
                {
                    if (XMLIterator.tagName.StartsWith("color") || XMLIterator.tagName.StartsWith("b") || XMLIterator.tagName.StartsWith("i") || XMLIterator.tagName.StartsWith("size"))
                    {
                        richXMLTagCount += XMLIterator.tagLength;
                    }
                }
            }
            _ResetSpriteTags(imgCount);
        }
예제 #3
0
파일: XML.cs 프로젝트: midgithub/notes
    void Parse(string aSource)
    {
        XML lastOpenNode = null;

        sNodeStack.Clear();

        XMLIterator.Begin(aSource);
        while (XMLIterator.NextTag())
        {
            if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
            {
                XML childNode;
                if (lastOpenNode != null)
                {
                    childNode = new XML();
                }
                else
                {
                    if (this.name != null)
                    {
                        Cleanup();
                        throw new Exception("Invalid xml format - no root node.");
                    }
                    childNode = this;
                }

                childNode.name        = XMLIterator.tagName;
                childNode._attributes = XMLIterator.GetAttributes(childNode._attributes);

                if (lastOpenNode != null)
                {
                    if (XMLIterator.tagType != XMLTagType.Void)
                    {
                        sNodeStack.Push(lastOpenNode);
                    }
                    if (lastOpenNode._children == null)
                    {
                        lastOpenNode._children = new XMLList();
                    }
                    lastOpenNode._children.Add(childNode);
                }
                if (XMLIterator.tagType != XMLTagType.Void)
                {
                    lastOpenNode = childNode;
                }
            }
            else if (XMLIterator.tagType == XMLTagType.End)
            {
                if (lastOpenNode == null || lastOpenNode.name != XMLIterator.tagName)
                {
                    Cleanup();
                    throw new Exception("Invalid xml format - <" + XMLIterator.tagName + "> dismatched.");
                }

                if (lastOpenNode._children == null || lastOpenNode._children.Count == 0)
                {
                    lastOpenNode.text = XMLIterator.GetText();
                }

                if (sNodeStack.Count > 0)
                {
                    lastOpenNode = sNodeStack.Pop();
                }
                else
                {
                    lastOpenNode = null;
                }
            }
        }
    }