1 //===-- StringList.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_StringList_h_
11 #define liblldb_StringList_h_
13 #include "llvm/ADT/StringRef.h"
19 namespace lldb_private {
22 namespace lldb_private {
26 namespace lldb_private {
32 explicit StringList(const char *str);
34 StringList(const char **strv, int strc);
36 virtual ~StringList();
38 void AppendString(const std::string &s);
40 void AppendString(std::string &&s);
42 void AppendString(const char *str);
44 void AppendString(const char *str, size_t str_len);
46 void AppendString(llvm::StringRef str);
48 void AppendList(const char **strv, int strc);
50 void AppendList(StringList strings);
52 size_t GetSize() const;
54 void SetSize(size_t n) { m_strings.resize(n); }
56 size_t GetMaxStringLength() const;
58 std::string &operator[](size_t idx) {
59 // No bounds checking, verify "idx" is good prior to calling this function
60 return m_strings[idx];
63 const std::string &operator[](size_t idx) const {
64 // No bounds checking, verify "idx" is good prior to calling this function
65 return m_strings[idx];
68 void PopBack() { m_strings.pop_back(); }
69 const char *GetStringAtIndex(size_t idx) const;
71 void Join(const char *separator, Stream &strm);
75 void LongestCommonPrefix(std::string &common_prefix);
77 void InsertStringAtIndex(size_t idx, const std::string &str);
79 void InsertStringAtIndex(size_t idx, std::string &&str);
81 void InsertStringAtIndex(size_t id, const char *str);
83 void DeleteStringAtIndex(size_t id);
85 void RemoveBlankLines();
87 size_t SplitIntoLines(const std::string &lines);
89 size_t SplitIntoLines(const char *lines, size_t len);
91 std::string CopyList(const char *item_preamble = nullptr,
92 const char *items_sep = "\n") const;
94 StringList &operator<<(const char *str);
96 StringList &operator<<(const std::string &s);
98 StringList &operator<<(StringList strings);
100 // Copy assignment for a vector of strings
101 StringList &operator=(const std::vector<std::string> &rhs);
103 // This string list contains a list of valid auto completion strings, and the
104 // "s" is passed in. "matches" is filled in with zero or more string values
105 // that start with "s", and the first string to exactly match one of the
106 // string values in this collection, will have "exact_matches_idx" filled in
107 // to match the index, or "exact_matches_idx" will have SIZE_MAX
108 size_t AutoComplete(llvm::StringRef s, StringList &matches,
109 size_t &exact_matches_idx) const;
111 // Dump the StringList to the given lldb_private::Log, `log`, one item per
112 // line. If given, `name` will be used to identify the start and end of the
113 // list in the output.
114 virtual void LogDump(Log *log, const char *name = nullptr);
116 // Static helper to convert an iterable of strings to a StringList, and then
117 // dump it with the semantics of the `LogDump` method.
118 template <typename T>
119 static void LogDump(Log *log, T s_iterable, const char *name = nullptr) {
122 // Make a copy of the iterable as a StringList
124 for (const auto &s : s_iterable)
127 l.LogDump(log, name);
131 std::vector<std::string> m_strings;
134 } // namespace lldb_private
136 #endif // liblldb_StringList_h_