Пример #1
0
        private void _ParseLinkTags(ref string strText)
        {
            if (string.IsNullOrEmpty(strText))
            {
                _ResetLinkTags(0);
                return;
            }
            mUnderlineTagInfos.Clear();
            int index = 0;

            mTextBuilder.Length = 0;
            var indexText = 0;

            foreach (Match match in LinkTag.GetMatches(strText))
            {
                mTextBuilder.Append(strText.Substring(indexText, match.Index - indexText));

                var     group = match.Groups[1];
                LinkTag tag   = _GetLinkTag(index);
                tag.SetStartIndex(mTextBuilder.Length * 4);
                tag.SetEndIndex((mTextBuilder.Length + match.Groups["text"].Length - 1) * 4 + 3);
                mUnderlineTagInfos.Add(tag);
                ++index;
                mTextBuilder.Append(match.Groups["text"].Value);
                indexText = match.Index + match.Length;
                tag.SetValue(match);
            }
            mTextBuilder.Append(strText.Substring(indexText, strText.Length - indexText));

            strText = mTextBuilder.ToString();

            _ResetLinkTags(index);
        }
Пример #2
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);
        }