Exemplo n.º 1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Show_complex -->
        /// <summary>
        ///      Returns a string displaying the endeme in the specified width
        /// </summary>
        /// <remarks>
        ///      112-2334-4556-6778-7654-321
        ///         1    3    5    4    2
        /// </remarks>
        /// <param name="width"></param>
        /// <param name="divs"></param>
        /// <param name="divider"></param>
        /// <returns></returns>
        public static string Show_complex(Endeme en, int width, int divs, string divider)
        {
            // --------------------------------------------------------------------------
            //  Handle some error conditions
            // --------------------------------------------------------------------------
            if (width <= 0)
            {
                return("");
            }
            if (en.IsEmpty)
            {
                return(divider.PadRight(divs, divider.ToCharArray()[0]).PadRight(width));
            }
            if (divs >= width)
            {
                return("".PadRight(width, divider.ToCharArray()[0]));
            }


            // --------------------------------------------------------------------------
            //  Calculate how many characteristics to show
            // --------------------------------------------------------------------------
            divs = Math.Min(5, divs);
            int num = width - divs * divider.Length;

            if (en.EnSet == null)
            {
                num = Math.Min(num, en.Count);
            }
            else
            {
                num = Math.Min(num, en.EnSet.Count);
            }


            // --------------------------------------------------------------------------
            //  Remove characters from the endeme string as necessary to format
            // --------------------------------------------------------------------------
            if (width <= 8)
            {
                return(EndemeFormat.Show_positive(en, width, divs, num, divider));
            }
            if (num < en.Length)
            {
                return(EndemeFormat.Show_partial(en, width, divs, num, divider));
            }
            else
            {
                return(EndemeFormat.Show_perfect(en, width, divs, num, divider));
            }
        }
Exemplo n.º 2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Show() -->
        /// <summary>
        ///      Returns a string displaying the N most important characteristics etc
        /// </summary>
        /// <param name="num"></param>
        /// <param name="width"></param>
        /// <param name="wordLen"></param>
        /// <returns></returns>
        /// <remarks>
        ///      Deprecated
        /// </remarks>
        public static string Show(Endeme en, int num, int width, string divider, int wordLen, string delim)
        {
            if (num > width)
            {
                num = width;
            }
            string        str     = "";
            string        pattern = "";
            string        replace = "";
            StringBuilder letters = new StringBuilder();


            if (en.IsEmpty)
            {
                str = "";
            }
            else
            {
                str = en; // new string(_string.ToArray());
                num = Math.Max(Math.Min(str.Length, num), 0);
                switch (width - num)
                {
                case 0:
                    letters = new StringBuilder(str);
                    break;

                case 1:
                case 2:
                    if (num > 5)
                    {
                        letters.Append(Regex.Replace(str, "^(...)(..)", "$1-$2"));
                    }
                    else
                    {
                        letters.Append(EndemeFormat.SetLength(num, str));
                    }
                    break;

                case 3:
                    switch (num)
                    {
                    case  0: pattern = "^.*$"; replace = ""; break;

                    case  1: pattern = "^(.).*$"; replace = "$1"; break;

                    case  2: pattern = "^(..).*$"; replace = "$1"; break;

                    case  3: pattern = "^(...).*$"; replace = "$1"; break;

                    case  4: pattern = "^(....).*$"; replace = "$1"; break;

                    case  5: pattern = "^(...)(..).*$"; replace = "$1-$2"; break;

                    case  6: pattern = "^(...)(...).*$"; replace = "$1-$2"; break;

                    case  7: pattern = "^(...)(....).*$"; replace = "$1-$2"; break;

                    case  8: pattern = "^(...)(.....).*$"; replace = "$1-$2"; break;

                    case  9: pattern = "^(...)(...).*(...)$"; replace = "$1-$2--$3"; break;

                    case 10: pattern = "^(...)(....).*(...)$"; replace = "$1-$2--$3"; break;

                    case 11: pattern = "^(...)(.....).*(...)$"; replace = "$1-$2--$3"; break;

                    case 12: pattern = "^(...)(....)(..).*(...)$"; replace = "$1-$2-$3-$4"; break;

                    case 13: pattern = "^(...)(....)(...).*(...)$"; replace = "$1-$2-$3-$4"; break;

                    case 14: pattern = "^(...)(....)(....).*(...)$"; replace = "$1-$2-$3-$4"; break;

                    case 15: pattern = "^(...)(....)(....).*(....)$"; replace = "$1-$2-$3-$4"; break;

                    case 16: pattern = "^(...)(....)(....).*(.....)$"; replace = "$1-$2-$3-$4"; break;

                    case 17: pattern = "^(...)(....)(....).*(......)$"; replace = "$1-$2-$3-$4"; break;

                    case 18: pattern = "^(...)(....)(....).*(.......)$"; replace = "$1-$2-$3-$4"; break;

                    case 19: pattern = "^(...)(....)(....).*(........)$"; replace = "$1-$2-$3-$4"; break;

                    case 20: pattern = "^(...)(....)(......).*(.......)$"; replace = "$1-$2-$3-$4"; break;

                    case 21: pattern = "^(...)(....)(.......).*(.......)$"; replace = "$1-$2-$3-$4"; break;

                    case 22: pattern = "^(...)(....)(........).*(.......)$"; replace = "$1-$2-$3-$4"; break;

                    default: pattern = "^(...)(....)(.......*)(.......)$"; replace = "$1-$2-$3-$4"; break;
                    }
                    letters.Append(Regex.Replace(str, pattern, replace));
                    break;

                //  case 4 :
                //      switch(num)
                //      {
                //          case  0 : pattern = "^.*$"                                  ; replace = ""              ; break;
                //          case  1 : pattern = "^(.).*$"                               ; replace = "$1"            ; break;
                //          case  2 : pattern = "^(..).*$"                              ; replace = "$1"            ; break;
                //          case  3 : pattern = "^(...).*$"                             ; replace = "$1"            ; break;
                //          case  4 : pattern = "^(....).*$"                            ; replace = "$1"            ; break;
                //          case  5 : pattern = "^(...)(..).*$"                         ; replace = "$1-$2"         ; break;
                //          case  6 : pattern = "^(...)(...).*$"                        ; replace = "$1-$2"         ; break;
                //          case  7 : pattern = "^(...)(....).*$"                       ; replace = "$1-$2"         ; break;
                //          case  8 : pattern = "^(...)(.....).*$"                      ; replace = "$1-$2"         ; break;
                //          case  9 : pattern = "^(...)(...).*(...)$"                   ; replace = "$1-$2---$3"    ; break;
                //          case 10 : pattern = "^(...)(....).*(...)$"                  ; replace = "$1-$2---$3"    ; break;
                ///* TAG */ case 11 : pattern = "^(...)(.....).*(...)$"                 ; replace = "$1-$2---$3"    ; break;
                //          case 12 : pattern = "^(...)(....)(..).*(...)$"              ; replace = "$1-$2-$3--$4"  ; break;
                //          case 13 : pattern = "^(...)(....)(...).*(...)$"             ; replace = "$1-$2-$3--$4"  ; break;
                //          case 14 : pattern = "^(...)(....)(....).*(...)$"            ; replace = "$1-$2-$3--$4"  ; break;
                //          case 15 : pattern = "^(...)(....)(....).*(....)$"           ; replace = "$1-$2-$3--$4"  ; break;
                //          case 16 : pattern = "^(...)(....)(....).*(.....)$"          ; replace = "$1-$2-$3--$4"  ; break;
                //          case 17 : pattern = "^(...)(....)(....).*(......)$"         ; replace = "$1-$2-$3--$4"  ; break;
                //          case 18 : pattern = "^(...)(....)(....).*(.......)$"        ; replace = "$1-$2-$3--$4"  ; break;
                //          case 19 : pattern = "^(...)(....)(....).*(........)$"       ; replace = "$1-$2-$3--$4"  ; break;
                //          case 20 : pattern = "^(...)(....)(......).*(....)(...)$"    ; replace = "$1-$2-$3-$4-$5"; break;
                //          case 21 : pattern = "^(...)(....)(.......).*(....)(...)$"   ; replace = "$1-$2-$3-$4-$5"; break;
                //          case 22 : pattern = "^(...)(....)(........).*(....)(...)$"  ; replace = "$1-$2-$3-$4-$5"; break;
                //          default : pattern = "^(...)(....)(.......*)(....)(...)$"    ; replace = "$1-$2-$3-$4-$5"; break;
                //      }
                //      letters.Append(Regex.Replace(str, pattern, replace));
                //      break;
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                    switch (num)
                    {
                    case  0: pattern = "^.*$"; replace = ""; break;

                    case  1: pattern = "^(.).*$"; replace = "$1"; break;

                    case  2: pattern = "^(..).*$"; replace = "$1"; break;

                    case  3: pattern = "^(...).*$"; replace = "$1"; break;

                    case  4: pattern = "^(....).*$"; replace = "$1"; break;

                    case  5: pattern = "^(...)(..).*$"; replace = "$1-$2"; break;

                    case  6: pattern = "^(...)(...).*$"; replace = "$1-$2"; break;

                    case  7: pattern = "^(...)(....).*$"; replace = "$1-$2"; break;

                    case  8: pattern = "^(...)(.....).*$"; replace = "$1-$2"; break;

                    case  9: pattern = "^(...)(...).*(...)$"; replace = "$1-$2----$3"; break;

                    case 10: pattern = "^(...)(....).*(...)$"; replace = "$1-$2----$3"; break;

                    case 11: pattern = "^(...)(.....).*(...)$"; replace = "$1-$2----$3"; break;

                    case 12: pattern = "^(...)(....)(..).*(...)$"; replace = "$1-$2-$3---$4"; break;

                    case 13: pattern = "^(...)(....)(...).*(...)$"; replace = "$1-$2-$3---$4"; break;

                    case 14: pattern = "^(...)(....)(....).*(...)$"; replace = "$1-$2-$3---$4"; break;

                    case 15: pattern = "^(...)(....)(....).*(....)$"; replace = "$1-$2-$3---$4"; break;

                    case 16: pattern = "^(...)(....)(....).*(..)(...)$"; replace = "$1-$2-$3--$4-$5"; break;

                    case 17: pattern = "^(...)(....)(....).*(...)(...)$"; replace = "$1-$2-$3--$4-$5"; break;

                    case 18: pattern = "^(...)(....)(....).*(....)(...)$"; replace = "$1-$2-$3--$4-$5"; break;

                    case 19: pattern = "^(...)(....)(....).*(.....)(...)$"; replace = "$1-$2-$3--$4-$5"; break;

                    case 20: pattern = "^(...)(....)(....)(..).*(....)(...)$"; replace = "$1-$2-$3-$4-$5-$6"; break;

                    case 21: pattern = "^(...)(....)(....)(...).*(....)(...)$"; replace = "$1-$2-$3-$4-$5-$6"; break;

                    case 22: pattern = "^(...)(....)(....)(....).*(....)(...)$"; replace = "$1-$2-$3-$4-$5-$6"; break;

                    default: pattern = "^(...)(....)(....)(...*)(....)(...)$"; replace = "$1-$2-$3-$4-$5-$6"; break;
                    }
                    letters.Append(Regex.Replace(str, pattern, replace));
                    break;

                case 4:
                default:
                    switch (num)
                    {
                    case  0: pattern = "^.*$"; replace = ""; break;

                    case  1: pattern = "^(.).*$"; replace = "$1"; break;

                    case  2: pattern = "^(..).*$"; replace = "$1"; break;

                    case  3: pattern = "^(...).*$"; replace = "$1"; break;

                    case  4: pattern = "^(....).*$"; replace = "$1"; break;

                    case  5: pattern = "^(...)(..).*$"; replace = "$1-$2"; break;

                    case  6: pattern = "^(...)(...).*$"; replace = "$1-$2"; break;

                    case  7: pattern = "^(...)(....).*$"; replace = "$1-$2"; break;

                    case  8: pattern = "^(...)(.....).*$"; replace = "$1-$2"; break;

                    case  9: pattern = "^(...)(...).*(...)$"; replace = "$1-$2--$3"; break;

                    case 10: pattern = "^(...)(....).*(...)$"; replace = "$1-$2--$3"; break;

                    /* TAG */         case 11: pattern = "^(...)(.....).*(...)$"; replace = "$1-$2--$3"; break;

                    case 12: pattern = "^(...)(....)(..).*(...)$"; replace = "$1-$2-$3--$4"; break;

                    case 13: pattern = "^(...)(....)(...).*(...)$"; replace = "$1-$2-$3--$4"; break;

                    case 14: pattern = "^(...)(....)(....).*(...)$"; replace = "$1-$2-$3--$4"; break;

                    case 15: pattern = "^(...)(....)(....).*(....)$"; replace = "$1-$2-$3--$4"; break;

                    case 16: pattern = "^(...)(....)(....).*(.....)$"; replace = "$1-$2-$3--$4"; break;

                    case 17: pattern = "^(...)(....)(....).*(......)$"; replace = "$1-$2-$3--$4"; break;

                    case 18: pattern = "^(...)(....)(....).*(.......)$"; replace = "$1-$2-$3--$4"; break;

                    case 19: pattern = "^(...)(....)(....).*(........)$"; replace = "$1-$2-$3--$4"; break;

                    case 20: pattern = "^(...)(....)(......).*(....)(...)$"; replace = "$1-$2-$3-$4-$5"; break;

                    case 21: pattern = "^(...)(....)(.......).*(....)(...)$"; replace = "$1-$2-$3-$4-$5"; break;

                    case 22: pattern = "^(...)(....)(........).*(....)(...)$"; replace = "$1-$2-$3-$4-$5"; break;

                    default: pattern = "^(...)(....)(.......*)(....)(...)$"; replace = "$1-$2-$3-$4-$5"; break;
                    }
                    letters.Append(Regex.Replace(str, pattern, replace));
                    break;
                }
            }


            // -------------------------------------------------------------------------
            //  Add some words if there is room
            // -------------------------------------------------------------------------
            if (en.EnSet != null && width > letters.Length + 5)
            {
                string d = divider;
                for (int i = 0; i < en.Count && i < 7; ++i)
                {
                    letters.Append(d + EndemeFormat.SetLength(wordLen, en.EnSet.Characteristic[en[i]].Label));
                    d = delim;
                }
                d = divider;
                for (int i = Math.Max(0, en.Count - 3); i < en.Count; ++i)
                {
                    char   ch    = en[i];
                    string addme = en.EnSet.Characteristic[ch].Label;
                    addme = Regex.Replace(addme, "^.* vs ", "-");
                    letters.Append(d + EndemeFormat.SetLength(wordLen, addme));
                    d = delim;
                }
                d = divider;
                for (int i = 7; i < en.Count - 3; ++i)
                {
                    letters.Append(d + EndemeFormat.SetLength(wordLen, en.EnSet.Characteristic[en[i]].Label));
                    d = delim;
                }
            }
            return(EndemeFormat.SetLength(width, letters.ToString()));
        }