Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:58

0001 //===-- StringList.h --------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_STRINGLIST_H
0010 #define LLDB_UTILITY_STRINGLIST_H
0011 
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/ADT/Twine.h"
0014 
0015 #include <cstddef>
0016 #include <string>
0017 #include <vector>
0018 
0019 namespace lldb_private {
0020 class Log;
0021 class Stream;
0022 }
0023 
0024 namespace lldb_private {
0025 
0026 class StringList {
0027   typedef std::vector<std::string> collection;
0028 
0029 public:
0030   StringList();
0031 
0032   explicit StringList(const char *str);
0033 
0034   StringList(const char **strv, int strc);
0035 
0036   virtual ~StringList();
0037 
0038   void AppendString(const std::string &s);
0039 
0040   void AppendString(std::string &&s);
0041 
0042   void AppendString(const char *str);
0043 
0044   void AppendString(const char *str, size_t str_len);
0045 
0046   void AppendString(llvm::StringRef str);
0047 
0048   void AppendString(const llvm::Twine &str);
0049 
0050   void AppendList(const char **strv, int strc);
0051 
0052   void AppendList(StringList strings);
0053 
0054   size_t GetSize() const;
0055 
0056   void SetSize(size_t n) { m_strings.resize(n); }
0057 
0058   size_t GetMaxStringLength() const;
0059 
0060   typedef collection::iterator iterator;
0061   typedef collection::const_iterator const_iterator;
0062 
0063   iterator begin() { return m_strings.begin(); }
0064   iterator end() { return m_strings.end(); }
0065   const_iterator begin() const { return m_strings.begin(); }
0066   const_iterator end() const { return m_strings.end(); }
0067 
0068   std::string &operator[](size_t idx) {
0069     // No bounds checking, verify "idx" is good prior to calling this function
0070     return m_strings[idx];
0071   }
0072 
0073   const std::string &operator[](size_t idx) const {
0074     // No bounds checking, verify "idx" is good prior to calling this function
0075     return m_strings[idx];
0076   }
0077 
0078   void PopBack() { m_strings.pop_back(); }
0079   const char *GetStringAtIndex(size_t idx) const;
0080 
0081   void Join(const char *separator, Stream &strm);
0082 
0083   void Clear();
0084 
0085   std::string LongestCommonPrefix();
0086 
0087   void InsertStringAtIndex(size_t idx, const std::string &str);
0088 
0089   void InsertStringAtIndex(size_t idx, std::string &&str);
0090 
0091   void InsertStringAtIndex(size_t id, const char *str);
0092 
0093   void DeleteStringAtIndex(size_t id);
0094 
0095   void RemoveBlankLines();
0096 
0097   size_t SplitIntoLines(const std::string &lines);
0098 
0099   size_t SplitIntoLines(const char *lines, size_t len);
0100 
0101   std::string CopyList(const char *item_preamble = nullptr,
0102                        const char *items_sep = "\n") const;
0103 
0104   StringList &operator<<(const char *str);
0105 
0106   StringList &operator<<(const std::string &s);
0107 
0108   StringList &operator<<(const StringList &strings);
0109 
0110   // Copy assignment for a vector of strings
0111   StringList &operator=(const std::vector<std::string> &rhs);
0112 
0113   // Dump the StringList to the given lldb_private::Log, `log`, one item per
0114   // line. If given, `name` will be used to identify the start and end of the
0115   // list in the output.
0116   virtual void LogDump(Log *log, const char *name = nullptr);
0117 
0118   // Static helper to convert an iterable of strings to a StringList, and then
0119   // dump it with the semantics of the `LogDump` method.
0120   template <typename T>
0121   static void LogDump(Log *log, T s_iterable, const char *name = nullptr) {
0122     if (!log)
0123       return;
0124     // Make a copy of the iterable as a StringList
0125     StringList l{};
0126     for (const auto &s : s_iterable)
0127       l << s;
0128 
0129     l.LogDump(log, name);
0130   }
0131 
0132 private:
0133   collection m_strings;
0134 };
0135 
0136 } // namespace lldb_private
0137 
0138 #endif // LLDB_UTILITY_STRINGLIST_H