diff options
author | Chaoren Lin <chaorenl@google.com> | 2015-06-05 00:28:06 +0000 |
---|---|---|
committer | Chaoren Lin <chaorenl@google.com> | 2015-06-05 00:28:06 +0000 |
commit | 0c5a9c147681445861c8589685ee57d4aeb0a6e3 (patch) | |
tree | 417ace2f4a1271d774b58354307ade4f70d722b3 /lldb/source/Host/common/FileSpec.cpp | |
parent | 8af9166efe853d9bfdb33dd49bd3024e248ff53b (diff) | |
download | bcm5719-llvm-0c5a9c147681445861c8589685ee57d4aeb0a6e3.tar.gz bcm5719-llvm-0c5a9c147681445861c8589685ee57d4aeb0a6e3.zip |
Delegate path operations to FileSpec.
Summary:
- Added PrependPathComponent utility functions to FileSpec.
- Delegate path operations in ParseCompileUnit to FileSpec.
- Delegate path operations in ParseSupportFiles to FileSpec.
Reviewers: clayborg, vharron, ovyalov
Reviewed By: ovyalov
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D10253
llvm-svn: 239127
Diffstat (limited to 'lldb/source/Host/common/FileSpec.cpp')
-rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 1b5ec3339a6..c3b6aa5e8ff 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -1362,21 +1362,54 @@ FileSpec::GetLastPathComponent () const } void -FileSpec::AppendPathComponent (const char *new_path) +FileSpec::PrependPathComponent(const char *new_path) { + if (!new_path) return; const bool resolve = false; if (m_filename.IsEmpty() && m_directory.IsEmpty()) { - SetFile(new_path,resolve); + SetFile(new_path, resolve); return; } StreamString stream; if (m_filename.IsEmpty()) - stream.Printf("%s/%s",m_directory.GetCString(),new_path); + stream.Printf("%s/%s", new_path, m_directory.GetCString()); else if (m_directory.IsEmpty()) - stream.Printf("%s/%s",m_filename.GetCString(),new_path); + stream.Printf("%s/%s", new_path, m_filename.GetCString()); else - stream.Printf("%s/%s/%s",m_directory.GetCString(), m_filename.GetCString(),new_path); + stream.Printf("%s/%s/%s", new_path, m_directory.GetCString(), m_filename.GetCString()); + SetFile(stream.GetData(), resolve); +} + +void +FileSpec::PrependPathComponent(const std::string &new_path) +{ + return PrependPathComponent(new_path.c_str()); +} + +void +FileSpec::PrependPathComponent(const FileSpec &new_path) +{ + return PrependPathComponent(new_path.GetPath(false)); +} + +void +FileSpec::AppendPathComponent(const char *new_path) +{ + if (!new_path) return; + const bool resolve = false; + if (m_filename.IsEmpty() && m_directory.IsEmpty()) + { + SetFile(new_path, resolve); + return; + } + StreamString stream; + if (m_filename.IsEmpty()) + stream.Printf("%s/%s", m_directory.GetCString(), new_path); + else if (m_directory.IsEmpty()) + stream.Printf("%s/%s", m_filename.GetCString(), new_path); + else + stream.Printf("%s/%s/%s", m_directory.GetCString(), m_filename.GetCString(), new_path); SetFile(stream.GetData(), resolve); } @@ -1387,6 +1420,12 @@ FileSpec::AppendPathComponent(const std::string &new_path) } void +FileSpec::AppendPathComponent(const FileSpec &new_path) +{ + return AppendPathComponent(new_path.GetPath(false)); +} + +void FileSpec::RemoveLastPathComponent () { const bool resolve = false; |