summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/source/Breakpoint/Watchpoint.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp
index d4c099be0c1..a9fe4ee4a22 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -95,6 +95,17 @@ Watchpoint::SetWatchSpec (const std::string &str)
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 @@ Watchpoint::GetOldSnapshot() const
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 @@ void
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
OpenPOWER on IntegriCloud