コード例 #1
0
        static string SetWidth(string str, TextWidthDialog.Result result, int value)
        {
            if (str.Length == value)
            {
                return(str);
            }

            if (str.Length > value)
            {
                switch (result.Location)
                {
                case TextWidthDialog.TextLocation.Start: return(str.Substring(0, value));

                case TextWidthDialog.TextLocation.Middle: return(str.Substring((str.Length - value) / 2, value));

                case TextWidthDialog.TextLocation.End: return(str.Substring(str.Length - value));

                default: throw new ArgumentException("Invalid");
                }
            }
            else
            {
                var len = value - str.Length;
                switch (result.Location)
                {
                case TextWidthDialog.TextLocation.Start: return(str + new string(result.PadChar, len));

                case TextWidthDialog.TextLocation.Middle: return(new string(result.PadChar, len / 2) + str + new string(result.PadChar, (len + 1) / 2));

                case TextWidthDialog.TextLocation.End: return(new string(result.PadChar, len) + str);

                default: throw new ArgumentException("Invalid");
                }
            }
        }
コード例 #2
0
        void Command_Text_Select_ByWidth(TextWidthDialog.Result result)
        {
            var results = GetFixedExpressionResults <int>(result.Expression);

            SetSelections(Selections.AsParallel().AsOrdered().Where((range, index) => range.Length == results[index]).ToList());
        }
コード例 #3
0
        void Command_Text_Width(TextWidthDialog.Result result)
        {
            var results = GetFixedExpressionResults <int>(result.Expression);

            ReplaceSelections(Selections.AsParallel().AsOrdered().Select((range, index) => SetWidth(GetString(range), result, results[index])).ToList());
        }