StringList.h revision 269024
1//===-- StringList.h --------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_StringList_h_
11#define liblldb_StringList_h_
12
13#include <stdint.h>
14
15#include "lldb/Core/STLUtils.h"
16#include "lldb/lldb-forward.h"
17
18namespace lldb_private {
19
20class StringList
21{
22public:
23
24    StringList ();
25
26    StringList (const char *str);
27
28    StringList (const char **strv, int strc);
29
30    virtual
31    ~StringList ();
32
33    void
34    AppendString (const std::string &s);
35
36    void
37    AppendString (std::string &&s);
38
39    void
40    AppendString (const char *str);
41
42    void
43    AppendString (const char *str, size_t str_len);
44
45    void
46    AppendList (const char ** strv, int strc);
47
48    void
49    AppendList (StringList strings);
50
51    bool
52    ReadFileLines (FileSpec &input_file);
53
54    size_t
55    GetSize () const;
56
57    void
58    SetSize (size_t n)
59    {
60        m_strings.resize(n);
61    }
62
63    size_t
64    GetMaxStringLength () const;
65
66    std::string &
67    operator [](size_t idx)
68    {
69        // No bounds checking, verify "idx" is good prior to calling this function
70        return m_strings[idx];
71    }
72
73    const std::string &
74    operator [](size_t idx) const
75    {
76        // No bounds checking, verify "idx" is good prior to calling this function
77        return m_strings[idx];
78    }
79
80    void
81    PopBack ()
82    {
83        m_strings.pop_back();
84    }
85    const char *
86    GetStringAtIndex (size_t idx) const;
87
88    void
89    Join (const char *separator, Stream &strm);
90
91    void
92    Clear ();
93
94    void
95    LongestCommonPrefix (std::string &common_prefix);
96
97    void
98    InsertStringAtIndex (size_t idx, const std::string &str);
99
100    void
101    InsertStringAtIndex (size_t idx, std::string &&str);
102
103    void
104    InsertStringAtIndex (size_t id, const char *str);
105
106    void
107    DeleteStringAtIndex (size_t id);
108
109    void
110    RemoveBlankLines ();
111
112    size_t
113    SplitIntoLines (const std::string &lines);
114
115    size_t
116    SplitIntoLines (const char *lines, size_t len);
117
118    std::string
119    CopyList(const char* item_preamble = NULL,
120             const char* items_sep = "\n") const;
121
122    StringList&
123    operator << (const char* str);
124
125    StringList&
126    operator << (StringList strings);
127
128    // This string list contains a list of valid auto completion
129    // strings, and the "s" is passed in. "matches" is filled in
130    // with zero or more string values that start with "s", and
131    // the first string to exactly match one of the string
132    // values in this collection, will have "exact_matches_idx"
133    // filled in to match the index, or "exact_matches_idx" will
134    // have SIZE_MAX
135    size_t
136    AutoComplete (const char *s,
137                  StringList &matches,
138                  size_t &exact_matches_idx) const;
139
140private:
141
142    STLStringArray m_strings;
143};
144
145} // namespace lldb_private
146
147#endif // liblldb_StringList_h_
148