summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/StringList.cpp
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Core/StringList.cpp
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/source/Core/StringList.cpp')
-rw-r--r--lldb/source/Core/StringList.cpp494
1 files changed, 200 insertions, 294 deletions
diff --git a/lldb/source/Core/StringList.cpp b/lldb/source/Core/StringList.cpp
index 98a079007fb..5085c439d0e 100644
--- a/lldb/source/Core/StringList.cpp
+++ b/lldb/source/Core/StringList.cpp
@@ -9,369 +9,275 @@
#include "lldb/Core/StringList.h"
+#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Host/FileSpec.h"
-#include "lldb/Core/Log.h"
#include <string>
using namespace lldb_private;
-StringList::StringList () :
- m_strings ()
-{
-}
+StringList::StringList() : m_strings() {}
-StringList::StringList (const char *str) :
- m_strings ()
-{
- if (str)
- m_strings.push_back (str);
+StringList::StringList(const char *str) : m_strings() {
+ if (str)
+ m_strings.push_back(str);
}
-StringList::StringList (const char **strv, int strc) :
- m_strings ()
-{
- for (int i = 0; i < strc; ++i)
- {
- if (strv[i])
- m_strings.push_back (strv[i]);
- }
+StringList::StringList(const char **strv, int strc) : m_strings() {
+ for (int i = 0; i < strc; ++i) {
+ if (strv[i])
+ m_strings.push_back(strv[i]);
+ }
}
-StringList::~StringList ()
-{
-}
+StringList::~StringList() {}
-void
-StringList::AppendString (const char *str)
-{
- if (str)
- m_strings.push_back (str);
+void StringList::AppendString(const char *str) {
+ if (str)
+ m_strings.push_back(str);
}
-void
-StringList::AppendString (const std::string &s)
-{
- m_strings.push_back (s);
-}
+void StringList::AppendString(const std::string &s) { m_strings.push_back(s); }
-void
-StringList::AppendString (std::string &&s)
-{
- m_strings.push_back (s);
-}
+void StringList::AppendString(std::string &&s) { m_strings.push_back(s); }
-void
-StringList::AppendString (const char *str, size_t str_len)
-{
- if (str)
- m_strings.push_back (std::string (str, str_len));
+void StringList::AppendString(const char *str, size_t str_len) {
+ if (str)
+ m_strings.push_back(std::string(str, str_len));
}
-void
-StringList::AppendString(llvm::StringRef str)
-{
- m_strings.push_back(str.str());
+void StringList::AppendString(llvm::StringRef str) {
+ m_strings.push_back(str.str());
}
-void
-StringList::AppendList (const char **strv, int strc)
-{
- for (int i = 0; i < strc; ++i)
- {
- if (strv[i])
- m_strings.push_back (strv[i]);
- }
+void StringList::AppendList(const char **strv, int strc) {
+ for (int i = 0; i < strc; ++i) {
+ if (strv[i])
+ m_strings.push_back(strv[i]);
+ }
}
-void
-StringList::AppendList (StringList strings)
-{
- size_t len = strings.GetSize();
+void StringList::AppendList(StringList strings) {
+ size_t len = strings.GetSize();
- for (size_t i = 0; i < len; ++i)
- m_strings.push_back (strings.GetStringAtIndex(i));
+ for (size_t i = 0; i < len; ++i)
+ m_strings.push_back(strings.GetStringAtIndex(i));
}
-bool
-StringList::ReadFileLines (FileSpec &input_file)
-{
- return input_file.ReadFileLines (m_strings);
+bool StringList::ReadFileLines(FileSpec &input_file) {
+ return input_file.ReadFileLines(m_strings);
}
-size_t
-StringList::GetSize () const
-{
- return m_strings.size();
+size_t StringList::GetSize() const { return m_strings.size(); }
+
+size_t StringList::GetMaxStringLength() const {
+ size_t max_length = 0;
+ for (const auto &s : m_strings) {
+ const size_t len = s.size();
+ if (max_length < len)
+ max_length = len;
+ }
+ return max_length;
}
-size_t
-StringList::GetMaxStringLength () const
-{
- size_t max_length = 0;
- for (const auto &s : m_strings)
- {
- const size_t len = s.size();
- if (max_length < len)
- max_length = len;
- }
- return max_length;
+const char *StringList::GetStringAtIndex(size_t idx) const {
+ if (idx < m_strings.size())
+ return m_strings[idx].c_str();
+ return NULL;
}
+void StringList::Join(const char *separator, Stream &strm) {
+ size_t size = GetSize();
-const char *
-StringList::GetStringAtIndex (size_t idx) const
-{
- if (idx < m_strings.size())
- return m_strings[idx].c_str();
- return NULL;
-}
+ if (size == 0)
+ return;
-void
-StringList::Join (const char *separator, Stream &strm)
-{
- size_t size = GetSize();
-
- if (size == 0)
- return;
-
- for (uint32_t i = 0; i < size; ++i)
- {
- if (i > 0)
- strm.PutCString(separator);
- strm.PutCString(GetStringAtIndex(i));
- }
+ for (uint32_t i = 0; i < size; ++i) {
+ if (i > 0)
+ strm.PutCString(separator);
+ strm.PutCString(GetStringAtIndex(i));
+ }
}
-void
-StringList::Clear ()
-{
- m_strings.clear();
-}
+void StringList::Clear() { m_strings.clear(); }
-void
-StringList::LongestCommonPrefix (std::string &common_prefix)
-{
- const size_t num_strings = m_strings.size();
+void StringList::LongestCommonPrefix(std::string &common_prefix) {
+ const size_t num_strings = m_strings.size();
- if (num_strings == 0)
- {
- common_prefix.clear();
- }
- else
- {
- common_prefix = m_strings.front();
-
- for (size_t idx = 1; idx < num_strings; ++idx)
- {
- std::string &curr_string = m_strings[idx];
- size_t new_size = curr_string.size();
-
- // First trim common_prefix if it is longer than the current element:
- if (common_prefix.size() > new_size)
- common_prefix.erase (new_size);
-
- // Then trim it at the first disparity:
- for (size_t i = 0; i < common_prefix.size(); i++)
- {
- if (curr_string[i] != common_prefix[i])
- {
- common_prefix.erase(i);
- break;
- }
- }
-
- // If we've emptied the common prefix, we're done.
- if (common_prefix.empty())
- break;
+ if (num_strings == 0) {
+ common_prefix.clear();
+ } else {
+ common_prefix = m_strings.front();
+
+ for (size_t idx = 1; idx < num_strings; ++idx) {
+ std::string &curr_string = m_strings[idx];
+ size_t new_size = curr_string.size();
+
+ // First trim common_prefix if it is longer than the current element:
+ if (common_prefix.size() > new_size)
+ common_prefix.erase(new_size);
+
+ // Then trim it at the first disparity:
+ for (size_t i = 0; i < common_prefix.size(); i++) {
+ if (curr_string[i] != common_prefix[i]) {
+ common_prefix.erase(i);
+ break;
}
- }
-}
+ }
-void
-StringList::InsertStringAtIndex (size_t idx, const char *str)
-{
- if (str)
- {
- if (idx < m_strings.size())
- m_strings.insert (m_strings.begin() + idx, str);
- else
- m_strings.push_back (str);
+ // If we've emptied the common prefix, we're done.
+ if (common_prefix.empty())
+ break;
}
+ }
}
-void
-StringList::InsertStringAtIndex (size_t idx, const std::string &str)
-{
+void StringList::InsertStringAtIndex(size_t idx, const char *str) {
+ if (str) {
if (idx < m_strings.size())
- m_strings.insert (m_strings.begin() + idx, str);
+ m_strings.insert(m_strings.begin() + idx, str);
else
- m_strings.push_back (str);
+ m_strings.push_back(str);
+ }
}
-void
-StringList::InsertStringAtIndex (size_t idx, std::string &&str)
-{
- if (idx < m_strings.size())
- m_strings.insert (m_strings.begin() + idx, str);
- else
- m_strings.push_back (str);
+void StringList::InsertStringAtIndex(size_t idx, const std::string &str) {
+ if (idx < m_strings.size())
+ m_strings.insert(m_strings.begin() + idx, str);
+ else
+ m_strings.push_back(str);
}
-void
-StringList::DeleteStringAtIndex (size_t idx)
-{
- if (idx < m_strings.size())
- m_strings.erase (m_strings.begin() + idx);
+void StringList::InsertStringAtIndex(size_t idx, std::string &&str) {
+ if (idx < m_strings.size())
+ m_strings.insert(m_strings.begin() + idx, str);
+ else
+ m_strings.push_back(str);
}
-size_t
-StringList::SplitIntoLines (const std::string &lines)
-{
- return SplitIntoLines (lines.c_str(), lines.size());
+void StringList::DeleteStringAtIndex(size_t idx) {
+ if (idx < m_strings.size())
+ m_strings.erase(m_strings.begin() + idx);
}
-size_t
-StringList::SplitIntoLines (const char *lines, size_t len)
-{
- const size_t orig_size = m_strings.size();
-
- if (len == 0)
- return 0;
-
- const char *k_newline_chars = "\r\n";
- const char *p = lines;
- const char *end = lines + len;
- while (p < end)
- {
- size_t count = strcspn (p, k_newline_chars);
- if (count == 0)
- {
- if (p[count] == '\r' || p[count] == '\n')
- m_strings.push_back(std::string());
- else
- break;
- }
- else
- {
- if (p + count > end)
- count = end - p;
- m_strings.push_back(std::string(p, count));
- }
- if (p[count] == '\r' && p[count+1] == '\n')
- count++; // Skip an extra newline char for the DOS newline
- count++; // Skip the newline character
- p += count;
- }
- return m_strings.size() - orig_size;
+size_t StringList::SplitIntoLines(const std::string &lines) {
+ return SplitIntoLines(lines.c_str(), lines.size());
}
-void
-StringList::RemoveBlankLines ()
-{
- if (GetSize() == 0)
- return;
-
- size_t idx = 0;
- while (idx < m_strings.size())
- {
- if (m_strings[idx].empty())
- DeleteStringAtIndex(idx);
- else
- idx++;
+size_t StringList::SplitIntoLines(const char *lines, size_t len) {
+ const size_t orig_size = m_strings.size();
+
+ if (len == 0)
+ return 0;
+
+ const char *k_newline_chars = "\r\n";
+ const char *p = lines;
+ const char *end = lines + len;
+ while (p < end) {
+ size_t count = strcspn(p, k_newline_chars);
+ if (count == 0) {
+ if (p[count] == '\r' || p[count] == '\n')
+ m_strings.push_back(std::string());
+ else
+ break;
+ } else {
+ if (p + count > end)
+ count = end - p;
+ m_strings.push_back(std::string(p, count));
}
+ if (p[count] == '\r' && p[count + 1] == '\n')
+ count++; // Skip an extra newline char for the DOS newline
+ count++; // Skip the newline character
+ p += count;
+ }
+ return m_strings.size() - orig_size;
+}
+
+void StringList::RemoveBlankLines() {
+ if (GetSize() == 0)
+ return;
+
+ size_t idx = 0;
+ while (idx < m_strings.size()) {
+ if (m_strings[idx].empty())
+ DeleteStringAtIndex(idx);
+ else
+ idx++;
+ }
}
-std::string
-StringList::CopyList(const char* item_preamble, const char* items_sep) const
-{
- StreamString strm;
- for (size_t i = 0; i < GetSize(); i++)
- {
- if (i && items_sep && items_sep[0])
- strm << items_sep;
- if (item_preamble)
- strm << item_preamble;
- strm << GetStringAtIndex(i);
- }
- return std::string(strm.GetData());
+std::string StringList::CopyList(const char *item_preamble,
+ const char *items_sep) const {
+ StreamString strm;
+ for (size_t i = 0; i < GetSize(); i++) {
+ if (i && items_sep && items_sep[0])
+ strm << items_sep;
+ if (item_preamble)
+ strm << item_preamble;
+ strm << GetStringAtIndex(i);
+ }
+ return std::string(strm.GetData());
}
-StringList&
-StringList::operator << (const char* str)
-{
- AppendString(str);
- return *this;
+StringList &StringList::operator<<(const char *str) {
+ AppendString(str);
+ return *this;
}
-StringList&
-StringList::operator << (const std::string& str)
-{
- AppendString(str);
- return *this;
+StringList &StringList::operator<<(const std::string &str) {
+ AppendString(str);
+ return *this;
}
-StringList&
-StringList::operator << (StringList strings)
-{
- AppendList(strings);
- 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);
+StringList &StringList::operator=(const std::vector<std::string> &rhs) {
+ Clear();
+ for (const auto &s : rhs)
+ m_strings.push_back(s);
- return *this;
+ return *this;
}
-size_t
-StringList::AutoComplete (const char *s, StringList &matches, size_t &exact_idx) const
-{
- matches.Clear();
- exact_idx = SIZE_MAX;
- if (s && s[0])
- {
- const size_t s_len = strlen (s);
- const size_t num_strings = m_strings.size();
-
- for (size_t i=0; i<num_strings; ++i)
- {
- if (m_strings[i].find(s) == 0)
- {
- if (exact_idx == SIZE_MAX && m_strings[i].size() == s_len)
- exact_idx = matches.GetSize();
- matches.AppendString (m_strings[i]);
- }
- }
- }
- else
- {
- // No string, so it matches everything
- matches = *this;
- }
- return matches.GetSize();
-}
+size_t StringList::AutoComplete(const char *s, StringList &matches,
+ size_t &exact_idx) const {
+ matches.Clear();
+ exact_idx = SIZE_MAX;
+ if (s && s[0]) {
+ const size_t s_len = strlen(s);
+ const size_t num_strings = m_strings.size();
-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());
+ for (size_t i = 0; i < num_strings; ++i) {
+ if (m_strings[i].find(s) == 0) {
+ if (exact_idx == SIZE_MAX && m_strings[i].size() == s_len)
+ exact_idx = matches.GetSize();
+ matches.AppendString(m_strings[i]);
+ }
}
- if (name)
- strm.Printf("End %s.\n", name);
-
- log->Debug("%s", strm.GetData());
+ } else {
+ // No string, so it matches everything
+ matches = *this;
+ }
+ 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());
}
OpenPOWER on IntegriCloud