Пример #1
0
 /* Function: BuildWrappedTitle
  * Returns the title as HTML with zero-width spaces added so that long identifiers wrap.  It will also add a span surrounding
  * the qualifiers with a "Qualifier" CSS class.
  */
 public string BuildWrappedTitle(string title, WrappedTitleMode mode)
 {
     if (mode == WrappedTitleMode.None)
     {
         return(title.ToHTML());
     }
     else
     {
         StringBuilder output = new StringBuilder();
         AppendWrappedTitle(title, mode, output);
         return(output.ToString());
     }
 }
Пример #2
0
        /* Function: AppendWrappedTitle
         * Appends the title to the passed StringBuilder as HTML with zero-width spaces added so that long identifiers wrap.  It will
         * also add a span surrounding the qualifiers with a "Qualifier" CSS class.
         */
        public void AppendWrappedTitle(string title, WrappedTitleMode mode, StringBuilder output)
        {
            MatchCollection splitSymbols = null;
            int             splitCount   = 0;

            if (mode == WrappedTitleMode.Code)
            {
                splitSymbols = CodeSplitSymbolsRegex.Matches(title);
                splitCount   = splitSymbols.Count;
            }
            else if (mode == WrappedTitleMode.File)
            {
                splitSymbols = FileSplitSymbolsRegex.Matches(title);
                splitCount   = splitSymbols.Count;
            }


            // Don't count separators on the end of the string.

            if (splitCount > 0)
            {
                int endOfString = title.Length;

                for (int i = splitCount - 1; i >= 0; i--)
                {
                    if (splitSymbols[i].Index + splitSymbols[i].Length == endOfString)
                    {
                        splitCount--;
                        endOfString = splitSymbols[i].Index;
                    }
                    else
                    {
                        break;
                    }
                }
            }


            // Build the HTML.

            if (splitCount == 0)
            {
                output.Append(title.ToHTML());
            }
            else
            {
                int appendedSoFar = 0;
                output.Append("<span class=\"Qualifier\">");

                for (int i = 0; i < splitCount; i++)
                {
                    int    endOfSection = splitSymbols[i].Index + splitSymbols[i].Length;
                    string titleSection = title.Substring(appendedSoFar, endOfSection - appendedSoFar);
                    output.Append(titleSection.ToHTML());

                    if (i < splitCount - 1)
                    {
                        // Insert a zero-width space for wrapping.  We have to put the final one outside the closing </span> or
                        // Webkit browsers won't wrap on it.
                        output.Append("&#8203;");
                    }

                    appendedSoFar = endOfSection;
                }

                output.Append("</span>&#8203;");                  // zero-width space for wrapping

                output.Append(title.Substring(appendedSoFar).ToHTML());
            }
        }