[Lldb-commits] [lldb] [lldb] Remove redundant severity substring within a diagnostic message. (PR #76111)

Felipe de Azevedo Piovezan via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 21 13:57:58 PST 2023


================
@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto &diagnostic : Diagnostics()) {
-    ret.append(StringForSeverity(diagnostic->GetSeverity()));
-    ret.append(std::string(diagnostic->GetMessage()));
+    std::string message(diagnostic->GetMessage());
+    std::string searchable_message(diagnostic->GetMessage().lower());
+    std::string severity(StringForSeverity(diagnostic->GetSeverity()));
+
+    // Erase the (first) redundant severity string in the message.
+    size_t position = searchable_message.find(severity);
+    if (position != std::string::npos)
+      message.erase(position, severity.length());
+
+    ret.append(severity);
+    ret.append(message);
----------------
felipepiovezan wrote:

Oh, also `ret` breaks both promises: we modify it  a lot and we also extend its lifetime past the current function

https://github.com/llvm/llvm-project/pull/76111


More information about the lldb-commits mailing list