From 80b639cd40df427b9e325318efeec2d885a65f62 Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 6 Sep 2015 14:32:30 +0000 Subject: Vendor import of (stripped) lldb trunk r242221: https://llvm.org/svn/llvm-project/lldb/trunk@242221 --- source/Interpreter/CommandObject.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'source/Interpreter/CommandObject.cpp') diff --git a/source/Interpreter/CommandObject.cpp b/source/Interpreter/CommandObject.cpp index d67f76e..c0efd9e 100644 --- a/source/Interpreter/CommandObject.cpp +++ b/source/Interpreter/CommandObject.cpp @@ -10,6 +10,7 @@ #include "lldb/Interpreter/CommandObject.h" #include +#include #include #include @@ -921,6 +922,27 @@ ExprPathHelpTextCallback() } void +CommandObject::FormatLongHelpText (Stream &output_strm, const char *long_help) +{ + CommandInterpreter& interpreter = GetCommandInterpreter(); + std::stringstream lineStream (long_help); + std::string line; + while (std::getline (lineStream, line)) { + if (line.empty()) { + output_strm << "\n"; + continue; + } + size_t result = line.find_first_not_of (" \t"); + if (result == std::string::npos) { + result = 0; + } + std::string whitespace_prefix = line.substr (0, result); + std::string remainder = line.substr (result); + interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(), remainder.c_str()); + } +} + +void CommandObject::GenerateHelpText (CommandReturnObject &result) { GenerateHelpText(result.GetOutputStream()); @@ -947,7 +969,7 @@ CommandObject::GenerateHelpText (Stream &output_strm) const char *long_help = GetHelpLong(); if ((long_help != nullptr) && (strlen (long_help) > 0)) - output_strm.Printf ("\n%s", long_help); + FormatLongHelpText (output_strm, long_help); if (WantsRawCommandString() && !WantsCompletion()) { // Emit the message about using ' -- ' between the end of the command options and the raw input @@ -984,7 +1006,7 @@ CommandObject::GenerateHelpText (Stream &output_strm) const char *long_help = GetHelpLong(); if ((long_help != nullptr) && (strlen (long_help) > 0)) - output_strm.Printf ("%s", long_help); + FormatLongHelpText (output_strm, long_help); else if (WantsRawCommandString()) { std::string help_text (GetHelp()); -- cgit v1.1