bool IsEmpty() const;
- const char *FindString(const char *input_str) const;
+ llvm::Optional<llvm::StringRef> FindString(llvm::StringRef input_str) const;
- const char *GetStringAtIndex(size_t idx) const;
+ llvm::StringRef GetStringAtIndex(size_t idx) const;
- const char *operator[](size_t idx) const;
+ llvm::StringRef operator[](size_t idx) const;
- const char *GetRecentmostString() const;
+ llvm::StringRef GetRecentmostString() const;
- void AppendString(const std::string &str, bool reject_if_dupe = true);
+ void AppendString(llvm::StringRef str, bool reject_if_dupe = true);
void Clear();
return m_history.empty();
}
-const char *CommandHistory::FindString(const char *input_str) const {
+llvm::Optional<llvm::StringRef>
+CommandHistory::FindString(llvm::StringRef input_str) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (!input_str)
- return nullptr;
+ if (input_str.size() < 2)
+ return llvm::None;
+
if (input_str[0] != g_repeat_char)
- return nullptr;
- if (input_str[1] == '-') {
- bool success;
- size_t idx = StringConvert::ToUInt32(input_str + 2, 0, 0, &success);
- if (!success)
- return nullptr;
+ return llvm::None;
+
+ if (input_str[1] == g_repeat_char) {
+ if (m_history.empty())
+ return llvm::None;
+ return m_history.back();
+ }
+
+ input_str = input_str.drop_front();
+
+ size_t idx = 0;
+ if (input_str.front() == '-') {
+ if (input_str.drop_front(2).getAsInteger(0, idx))
+ return llvm::None;
if (idx > m_history.size())
- return nullptr;
+ return llvm::None;
idx = m_history.size() - idx;
- return m_history[idx].c_str();
+ return m_history[idx];
- } else if (input_str[1] == g_repeat_char) {
- if (m_history.empty())
- return nullptr;
- else
- return m_history.back().c_str();
} else {
- bool success;
- uint32_t idx = StringConvert::ToUInt32(input_str + 1, 0, 0, &success);
- if (!success)
- return nullptr;
+ if (input_str.drop_front().getAsInteger(0, idx))
+ return llvm::None;
+ if (idx > m_history.size())
+ return llvm::None;
if (idx >= m_history.size())
- return nullptr;
- return m_history[idx].c_str();
+ return llvm::None;
+ return m_history[idx];
}
}
-const char *CommandHistory::GetStringAtIndex(size_t idx) const {
+llvm::StringRef CommandHistory::GetStringAtIndex(size_t idx) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (idx < m_history.size())
- return m_history[idx].c_str();
- return nullptr;
+ return m_history[idx];
+ return "";
}
-const char *CommandHistory::operator[](size_t idx) const {
+llvm::StringRef CommandHistory::operator[](size_t idx) const {
return GetStringAtIndex(idx);
}
-const char *CommandHistory::GetRecentmostString() const {
+llvm::StringRef CommandHistory::GetRecentmostString() const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (m_history.empty())
- return nullptr;
- return m_history.back().c_str();
+ return "";
+ return m_history.back();
}
-void CommandHistory::AppendString(const std::string &str, bool reject_if_dupe) {
+void CommandHistory::AppendString(llvm::StringRef str, bool reject_if_dupe) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (reject_if_dupe) {
if (!m_history.empty()) {
return;
}
}
- m_history.push_back(std::string(str));
+ m_history.push_back(str);
}
void CommandHistory::Clear() {
else if (command_string[non_space] == m_comment_char)
comment_command = true;
else if (command_string[non_space] == CommandHistory::g_repeat_char) {
- const char *history_string =
- m_command_history.FindString(command_string.c_str() + non_space);
- if (history_string == nullptr) {
+ llvm::StringRef search_str(command_string);
+ search_str = search_str.drop_front(non_space);
+ if (auto hist_str = m_command_history.FindString(search_str)) {
+ add_to_history = false;
+ command_string = *hist_str;
+ original_command_string = *hist_str;
+ } else {
result.AppendErrorWithFormat("Could not find entry: %s in history",
command_string.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
- add_to_history = false;
- command_string = history_string;
- original_command_string = history_string;
}
}
if (first_arg[0] == m_comment_char)
return 0;
else if (first_arg[0] == CommandHistory::g_repeat_char) {
- const char *history_string = m_command_history.FindString(first_arg);
- if (history_string != nullptr) {
+ if (auto hist_str = m_command_history.FindString(first_arg)) {
matches.Clear();
- matches.InsertStringAtIndex(0, history_string);
+ matches.InsertStringAtIndex(0, *hist_str);
return -2;
} else
return 0;