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"
15 #include <stddef.h> // for size_t
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
104 // strings, and the "s" is passed in. "matches" is filled in
105 // with zero or more string values that start with "s", and
106 // the first string to exactly match one of the string
107 // values in this collection, will have "exact_matches_idx"
108 // filled in to match the index, or "exact_matches_idx" will
110 size_t AutoComplete(llvm::StringRef s, StringList &matches,
111 size_t &exact_matches_idx) const;
113 // Dump the StringList to the given lldb_private::Log, `log`, one item per
115 // If given, `name` will be used to identify the start and end of the list in
117 virtual void LogDump(Log *log, const char *name = nullptr);
119 // Static helper to convert an iterable of strings to a StringList, and then
120 // dump it with the semantics of the `LogDump` method.
121 template <typename T>
122 static void LogDump(Log *log, T s_iterable, const char *name = nullptr) {
125 // Make a copy of the iterable as a StringList
127 for (const auto &s : s_iterable)
130 l.LogDump(log, name);
134 std::vector<std::string> m_strings;
137 } // namespace lldb_private
139 #endif // liblldb_StringList_h_