This revision was automatically updated to reflect the committed changes.
Closed by commit rL256927: Add LogDump methods to lldb_private::StringList. 
(authored by EwanCrawford).

Changed prior to commit:
  http://reviews.llvm.org/D15773?vs=44000&id=44104#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D15773

Files:
  lldb/trunk/include/lldb/Core/StringList.h
  lldb/trunk/source/Core/StringList.cpp

Index: lldb/trunk/source/Core/StringList.cpp
===================================================================
--- lldb/trunk/source/Core/StringList.cpp
+++ lldb/trunk/source/Core/StringList.cpp
@@ -11,6 +11,8 @@
 
 #include "lldb/Core/StreamString.h"
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Core/StreamString.h"
 
 #include <string>
 
@@ -305,12 +307,29 @@
 }
 
 StringList&
+StringList::operator << (const std::string& str)
+{
+    AppendString(str);
+    return *this;
+}
+
+StringList&
 StringList::operator << (StringList strings)
 {
     AppendList(strings);
     return *this;
 }
 
+StringList&
+StringList::operator = (const std::vector<std::string> &rhs)
+{
+    Clear();
+    for (const auto &s : rhs)
+        m_strings.push_back(s);
+
+    return *this;
+}
+
 size_t
 StringList::AutoComplete (const char *s, StringList &matches, size_t &exact_idx) const
 {
@@ -339,3 +358,21 @@
     return matches.GetSize();
 }
 
+void
+StringList::LogDump(Log *log, const char *name)
+{
+    if (!log)
+        return;
+
+    StreamString strm;
+    if (name)
+        strm.Printf("Begin %s:\n", name);
+    for (const auto &s : m_strings) {
+        strm.Indent();
+        strm.Printf("%s\n", s.c_str());
+    }
+    if (name)
+        strm.Printf("End %s.\n", name);
+
+    log->Debug("%s", strm.GetData());
+}
Index: lldb/trunk/include/lldb/Core/StringList.h
===================================================================
--- lldb/trunk/include/lldb/Core/StringList.h
+++ lldb/trunk/include/lldb/Core/StringList.h
@@ -133,8 +133,15 @@
     operator << (const char* str);
 
     StringList&
+    operator << (const std::string &s);
+
+    StringList&
     operator << (StringList strings);
     
+    // Copy assignment for a vector of strings
+    StringList&
+    operator = (const std::vector<std::string> &rhs);
+
     // This string list contains a list of valid auto completion
     // strings, and the "s" is passed in. "matches" is filled in
     // with zero or more string values that start with "s", and
@@ -147,6 +154,23 @@
                   StringList &matches,
                   size_t &exact_matches_idx) const;
 
+    // Dump the StringList to the given lldb_private::Log, `log`, one item per line.
+    // If given, `name` will be used to identify the start and end of the list in the output.
+    virtual void LogDump(Log *log, const char *name = nullptr);
+
+    // Static helper to convert an iterable of strings to a StringList, and then
+    // dump it with the semantics of the `LogDump` method.
+    template<typename T> static void LogDump(Log *log, T s_iterable, const char *name = nullptr)
+    {
+        if (!log)
+            return;
+        // Make a copy of the iterable as a StringList
+        StringList l{};
+        for (const auto &s : s_iterable)
+            l << s;
+
+        l.LogDump(log, name);
+    }
 private:
     STLStringArray m_strings;
 };
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to