private static List <TypedTextSymbol> CreateSymbolListFromText(string text)
    {
        var symbolList       = new List <TypedTextSymbol>();
        int parsedCharacters = 0;

        while (parsedCharacters < text.Length)
        {
            TypedTextSymbol symbol = null;

            // Check for tags
            var remainingText = text.Substring(parsedCharacters, text.Length - parsedCharacters);
            if (RichTextTag.StringStartsWithTag(remainingText))
            {
                var tag = RichTextTag.ParseNext(remainingText);
                symbol = new TypedTextSymbol(tag);
            }
            else
            {
                symbol = new TypedTextSymbol(remainingText.Substring(0, 1));
            }

            parsedCharacters += symbol.Length;
            symbolList.Add(symbol);
        }

        return(symbolList);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 根据字符串创建文本标记
    /// </summary>
    /// <param name="_text"></param>
    /// <returns></returns>
    private static void CreateSymbolsFromText(string _text)
    {
        int textSymbolIndex  = 0;
        int parsedCharacters = 0;

        while (parsedCharacters < _text.Length)
        {
            TextSymbol symbol = null;

            // 检查富文本标签
            var remainingText = _text.Substring(parsedCharacters, _text.Length - parsedCharacters);
            if (RichTextTag.StringStartsWithTag(remainingText))
            {
                var tag = RichTextTag.ParseNext(remainingText);
                if (null != tag)
                {
                    // 富文本标签的文本标记
                    symbol     = GetTextSymbol(textSymbolIndex++);
                    symbol.Tag = tag;
                }
            }

            if (null == symbol)
            {
                // 普通字符的文本标记
                symbol           = GetTextSymbol(textSymbolIndex++);
                symbol.Character = remainingText.Substring(0, 1);
            }

            parsedCharacters += symbol.Length;
        }

        m_ValidTextSymbolCount = textSymbolIndex;
    }