diff options
| author | Bill Wendling <isanbard@gmail.com> | 2012-04-18 21:39:23 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2012-04-18 21:39:23 +0000 |
| commit | 392e4fbdd9b152efff4c051286f6b2c21270c902 (patch) | |
| tree | 4ac339be2c4c7c596f068b59d5e512b157c7b433 /lldb/source/Core/StringList.cpp | |
| parent | eb1c2bdc1f55fbc5d1e7bb86e9f0e038b0f5adb7 (diff) | |
Creating release_31 branchllvmorg-3.1.0-rc1
llvm-svn: 155059
llvm-svn: 155053
llvm-svn: 155051
Diffstat (limited to 'lldb/source/Core/StringList.cpp')
| -rw-r--r-- | lldb/source/Core/StringList.cpp | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/lldb/source/Core/StringList.cpp b/lldb/source/Core/StringList.cpp deleted file mode 100644 index 1df8b7b9a648..000000000000 --- a/lldb/source/Core/StringList.cpp +++ /dev/null @@ -1,239 +0,0 @@ -//===-- StringList.cpp ------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "lldb/Core/StringList.h" - -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" - -#include <string> - -using namespace lldb_private; - -StringList::StringList () : - m_strings () -{ -} - -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 () -{ -} - -void -StringList::AppendString (const char *str) -{ - if (str) - m_strings.push_back (str); -} - -void -StringList::AppendString (const char *str, size_t str_len) -{ - if (str) - m_strings.push_back (std::string (str, str_len)); -} - -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) -{ - uint32_t len = strings.GetSize(); - - for (uint32_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); -} - -uint32_t -StringList::GetSize () const -{ - return m_strings.size(); -} - -const char * -StringList::GetStringAtIndex (size_t idx) const -{ - if (idx < m_strings.size()) - return m_strings[idx].c_str(); - return NULL; -} - -void -StringList::Clear () -{ - m_strings.clear(); -} - -void -StringList::LongestCommonPrefix (std::string &common_prefix) -{ - //arg_sstr_collection::iterator pos, end = m_args.end(); - int pos = 0; - int end = m_strings.size(); - - if (pos == end) - common_prefix.clear(); - else - common_prefix = m_strings[pos]; - - for (++pos; pos != end; ++pos) - { - size_t new_size = strlen (m_strings[pos].c_str()); - - // 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 (m_strings[pos][i] != common_prefix[i]) - { - common_prefix.erase(i); - break; - } - } - - // If we've emptied the common prefix, we're done. - if (common_prefix.empty()) - 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); - } -} - -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; -} - -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) -{ - StreamString strm; - for (int 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 << (StringList strings) -{ - AppendList(strings); - return *this; -} |
