[Lldb-commits] [lldb] Colorize output when searching for symbols in	lldb (PR #69422)
    David Spickett via lldb-commits 
    lldb-commits at lists.llvm.org
       
    Tue Nov 14 01:34:18 PST 2023
    
    
  
================
@@ -403,9 +404,41 @@ bool Address::GetDescription(Stream &s, Target &target,
   return false;
 }
 
+void Address::DumpName(Stream *strm, llvm::StringRef text,
+                       const char *pattern) {
+  if (!pattern) {
+    strm->PutCString(text.data());
+    return;
+  }
+
+  llvm::Regex reg_pattern(pattern);
+  llvm::SmallVector<llvm::StringRef, 1> matches;
+  llvm::StringRef remaining = text;
+  std::string red_start =
+      lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}");
+  std::string reset_color =
+      lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}");
+
+  size_t last_pos = 0;
+  while (reg_pattern.match(remaining, &matches)) {
+    llvm::StringRef match = matches[0];
+    size_t match_start_pos = match.data() - text.data();
+    size_t match_end_pos = match_start_pos + match.size();
+
+    strm->Write(text.data() + last_pos, match_start_pos - last_pos);
----------------
DavidSpickett wrote:
Is `text.data() + last_pos` == `remaining` in this case? Maybe not but if it is it'd be a nice simplification.
https://github.com/llvm/llvm-project/pull/69422
    
    
More information about the lldb-commits
mailing list