[lldb/Core] Minor code cleanup in Editline.cpp (NFC)

Simplify the code a bit.

Differential revision: https://reviews.llvm.org/D75294
This commit is contained in:
Shu Anzai 2020-03-05 16:14:05 -08:00 committed by Jonas Devlieghere
parent dcba401a39
commit 467969161d
1 changed files with 5 additions and 8 deletions

View File

@ -144,10 +144,10 @@ std::vector<EditLineStringType> SplitLines(const EditLineStringType &input) {
while (start < input.length()) { while (start < input.length()) {
size_t end = input.find('\n', start); size_t end = input.find('\n', start);
if (end == std::string::npos) { if (end == std::string::npos) {
result.insert(result.end(), input.substr(start)); result.push_back(input.substr(start));
break; break;
} }
result.insert(result.end(), input.substr(start, end - start)); result.push_back(input.substr(start, end - start));
start = end + 1; start = end + 1;
} }
return result; return result;
@ -302,19 +302,16 @@ protected:
// Editline private methods // Editline private methods
void Editline::SetBaseLineNumber(int line_number) { void Editline::SetBaseLineNumber(int line_number) {
std::stringstream line_number_stream;
line_number_stream << line_number;
m_base_line_number = line_number; m_base_line_number = line_number;
m_line_number_digits = m_line_number_digits =
std::max(3, (int)line_number_stream.str().length() + 1); std::max<int>(3, std::to_string(line_number).length() + 1);
} }
std::string Editline::PromptForIndex(int line_index) { std::string Editline::PromptForIndex(int line_index) {
bool use_line_numbers = m_multiline_enabled && m_base_line_number > 0; bool use_line_numbers = m_multiline_enabled && m_base_line_number > 0;
std::string prompt = m_set_prompt; std::string prompt = m_set_prompt;
if (use_line_numbers && prompt.length() == 0) { if (use_line_numbers && prompt.length() == 0)
prompt = ": "; prompt = ": ";
}
std::string continuation_prompt = prompt; std::string continuation_prompt = prompt;
if (m_set_continuation_prompt.length() > 0) { if (m_set_continuation_prompt.length() > 0) {
continuation_prompt = m_set_continuation_prompt; continuation_prompt = m_set_continuation_prompt;
@ -429,7 +426,7 @@ void Editline::DisplayInput(int firstIndex) {
} }
int Editline::CountRowsForLine(const EditLineStringType &content) { int Editline::CountRowsForLine(const EditLineStringType &content) {
auto prompt = std::string prompt =
PromptForIndex(0); // Prompt width is constant during an edit session PromptForIndex(0); // Prompt width is constant during an edit session
int line_length = (int)(content.length() + prompt.length()); int line_length = (int)(content.length() + prompt.length());
return (line_length / m_terminal_width) + 1; return (line_length / m_terminal_width) + 1;