コード例 #1
0
    private static void IdTag(StringBuilder tag, out DescriptionProcess mode, out string replaceString, out int tagIndex)
    {
        replaceString = string.Empty;
        mode          = DescriptionProcess.kSearch;
        tagIndex      = -1;
        bool    flag  = tag[0] == '/';
        string  value = (!flag) ? tag.ToString() : tag.ToString(1, tag.Length - 1);
        int     num   = tags.Length;
        int     num2  = 0;
        TagData tagData;

        while (true)
        {
            if (num2 < num)
            {
                tagData = tags[num2];
                if (tagData.tag.Equals(value))
                {
                    break;
                }
                num2++;
                continue;
            }
            return;
        }
        mode          = tagData.mode;
        replaceString = ((!flag) ? tagData.replaceStart : tagData.replaceEnd);
        if (mode == DescriptionProcess.kSkipUntilEndIndex)
        {
            tagIndex = num2;
        }
    }
コード例 #2
0
    public static string RichTextProcess(string richText)
    {
        int num = richText.IndexOf('[');

        if (num == -1)
        {
            return(richText);
        }
        int                length         = richText.Length;
        StringBuilder      stringBuilder  = new StringBuilder(richText, 0, num, length);
        StringBuilder      stringBuilder2 = new StringBuilder(16);
        DescriptionProcess mode           = DescriptionProcess.kSearch;
        int                tagIndex       = -1;
        int                num2           = -1;
        bool               flag           = true;

        for (int i = num; i < length; i++)
        {
            char c = richText[i];
            switch (mode)
            {
            case DescriptionProcess.kSearch:
                if (c == '[')
                {
                    mode = DescriptionProcess.kBracketSearch;
                    stringBuilder2.Length = 0;
                    continue;
                }
                break;

            case DescriptionProcess.kBracketSearch:
                if (c == ']' || c == '=')
                {
                    IdTag(stringBuilder2, out mode, out string replaceString, out tagIndex);
                    if (flag)
                    {
                        stringBuilder.Append(replaceString);
                    }
                }
                else
                {
                    stringBuilder2.Append(c);
                }
                continue;

            case DescriptionProcess.kSkipUntilEndIndex:
                if (!flag && tagIndex == num2)
                {
                    flag = true;
                    mode = DescriptionProcess.kSearch;
                    num2 = -1;
                    continue;
                }
                num2     = tagIndex;
                tagIndex = -1;
                flag     = false;
                mode     = DescriptionProcess.kSearch;
                break;
            }
            if (flag)
            {
                stringBuilder.Append(c);
            }
        }
        return(stringBuilder.ToString());
    }