From: Ted Kremenek Date: Sun, 21 Sep 2008 18:52:59 +0000 (+0000) Subject: Added experimental "intelligent-sizing" of HTML message bubbles based on the contents... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6aa83e5c7e0bc07af0e41308f8e39a5ecd54f83;p=clang Added experimental "intelligent-sizing" of HTML message bubbles based on the contents of the message. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56400 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/HTMLDiagnostics.cpp b/lib/Driver/HTMLDiagnostics.cpp index 22d3da9320..c9739c4081 100644 --- a/lib/Driver/HTMLDiagnostics.cpp +++ b/lib/Driver/HTMLDiagnostics.cpp @@ -378,42 +378,84 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, unsigned BugFileID, PosNo += *c == '\t' ? 8 : 1; // Create the html for the message. - - std::string s; - llvm::raw_string_ostream os(s); - - os << "\n" - << "
"; - - if (max > 1) - os << "[" << num << "] "; - - os << html::EscapeText(P.getString()) << "
"; - - // Insert the new html. - - unsigned DisplayPos = 0; - - switch (P.getDisplayHint()) { - case PathDiagnosticPiece::Above: - DisplayPos = LineStart - FileStart; - break; - case PathDiagnosticPiece::Below: - DisplayPos = LineEnd - FileStart; - break; - default: - assert (false && "Unhandled hint."); - } + { + // Get the string and determining its maximum substring. + const std::string& Msg = P.getString(); + unsigned max_token = 0; + unsigned cnt = 0; + unsigned len = Msg.size(); + + for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I) + switch (*I) { + default: + ++cnt; + continue; + case ' ': + case '\t': + case '\n': + if (cnt > max_token) max_token = cnt; + cnt = 0; + } + + if (cnt > max_token) max_token = cnt; + + // Next, determine the approximate size of the message bubble in em. + unsigned em; + const unsigned max_line = 80; + + if (max_token >= max_line) + em = max_token / 2; + else { + unsigned characters = max_line; + unsigned lines = len / max_line; + + if (lines > 0) { + for (; characters > max_token; --characters) + if (len / characters > lines) { + ++characters; + break; + } + } + + em = characters / 2; + } + + // Now generate the message bubble. + std::string s; + llvm::raw_string_ostream os(s); + + os << "\n
"; + + if (max > 1) + os << "[" << num << "] "; + + os << html::EscapeText(Msg) << "
"; + + // Insert the new html. + unsigned DisplayPos = 0; + + switch (P.getDisplayHint()) { + case PathDiagnosticPiece::Above: + DisplayPos = LineStart - FileStart; + break; + case PathDiagnosticPiece::Below: + DisplayPos = LineEnd - FileStart; + break; + default: + assert (false && "Unhandled hint."); + } + + R.InsertStrBefore(SourceLocation::getFileLoc(FileID, DisplayPos), os.str()); + } // Now highlight the ranges.