A little bit of refactoring.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@161903 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Breakpoint/Watchpoint.cpp b/source/Breakpoint/Watchpoint.cpp
index d4c099b..a9fe4ee 100644
--- a/source/Breakpoint/Watchpoint.cpp
+++ b/source/Breakpoint/Watchpoint.cpp
@@ -95,6 +95,17 @@
return;
}
+// Strip at most one character from the end of the string.
+static inline std::string
+RStripOnce(const std::string &str, const char c)
+{
+ std::string res = str;
+ size_t len = res.length();
+ if (len && res.at(len - 1) == '\n')
+ res.resize(len - 1);
+ return res;
+}
+
std::string
Watchpoint::GetOldSnapshot() const
{
@@ -104,11 +115,7 @@
void
Watchpoint::SetOldSnapshot (const std::string &str)
{
- size_t len = str.length();
- m_snapshot_old_str = str;
- if (len && str.at(len - 1) == '\n')
- m_snapshot_old_str.resize(len - 1);
- return;
+ m_snapshot_old_str = RStripOnce(str, '\n');
}
std::string
@@ -121,11 +128,7 @@
Watchpoint::SetNewSnapshot (const std::string &str)
{
m_snapshot_old_str = m_snapshot_new_str;
- size_t len = str.length();
- m_snapshot_new_str = str;
- if (len && str.at(len - 1) == '\n')
- m_snapshot_new_str.resize(len - 1);
- return;
+ m_snapshot_new_str = RStripOnce(str, '\n');
}
uint64_t