コード例 #1
0
        /// <summary>
        /// Return the table from list of strings similar as result of: 'ls' command in bash
        /// </summary>
        /// <param name="words"></param>
        /// <param name="resultWidth"></param>
        /// <param name="colSpan"></param>
        /// <returns></returns>
        public static string[] BuildTable(string[] words, int colNum, int colWidth, int colSpan)
        {
            UnityEngine.Debug.Assert(colNum > 0);
            UnityEngine.Debug.Assert(colWidth > 0);
            var fullColWidth = colWidth + colSpan;

            // Note: shorter tat 4 characters words will not work with truncating
            // because: truncating add ellipse string to te end '...'
            UnityEngine.Debug.Assert(colWidth > 3);
            var nRows = words.Length / colNum;

            if (nRows * colNum < words.Length)
            {
                nRows++;
            }
            var result   = new string[nRows];
            var rowcount = 0;
            var colcount = 0;
            var sentence = string.Empty;

            foreach (var word in words)
            {
                if (word.Length > colWidth)
                {
                    sentence += Humanizer.Truncate(word, colWidth).PadRight(fullColWidth);
                }
                else
                {
                    sentence += word.PadRight(fullColWidth);
                }

                if (++colcount >= colNum)
                {
                    colcount           = 0;
                    result[rowcount++] = sentence;
                    sentence           = string.Empty;
                }
            }
            if (rowcount < result.Length)
            {
                result[rowcount] = sentence;
            }
            return(result);
        }
コード例 #2
0
 public void Truncate()
 {
     Assert.That(Humanizer.Truncate("Lorem Ipsum is simply dummy text.", 20),
                 Is.EqualTo("Lorem Ipsum is simpl..."));
 }