コード例 #1
0
        public string GetText(
            Capture capture,
            int matchNumber,
            string?groupName,
            int captureNumber,
            bool omitMatchInfo = false,
            bool omitGroupInfo = false)
        {
            StringBuilder sb = StringBuilderCache.GetInstance();

            if (omitMatchInfo)
            {
                sb.Append(MatchSpaces);
            }
            else
            {
                AppendNumber(Captions.ShortMatch, matchNumber, MatchWidth);
            }

            if (groupName != null)
            {
                if (omitGroupInfo)
                {
                    sb.Append(GroupSpaces);
                }
                else
                {
                    Append(Captions.ShortGroup, groupName, GroupWidth);
                }
            }

            if (captureNumber != -1 &&
                CaptureWidth > 0)
            {
                AppendNumber(Captions.ShortCapture, captureNumber, CaptureWidth);
            }

            AppendNumber(Captions.ShortIndex, capture.Index, IndexWidth);
            AppendNumber(Captions.ShortLength, capture.Length, LengthWidth);

            return(StringBuilderCache.GetStringAndFree(sb));

            void Append(string caption, string value, int width)
            {
                if (caption.Length > 0)
                {
                    sb.Append(caption);
                    sb.Append(PrefixSeparator);
                }

                sb.Append(value);
                sb.Append(' ', width - value.Length);
                sb.Append(ItemSeparator);
            }

            void AppendNumber(string caption, int number, int width)
            {
                if (caption.Length > 0)
                {
                    sb.Append(caption);
                    sb.Append(PrefixSeparator);
                }

                sb.Append(' ', width - number.GetDigitCount());
                sb.Append(number);
                sb.Append(ItemSeparator);
            }
        }