[Lldb-commits] [lldb] r286728 - Make CommandReturnObject methods accept StringRefs.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Sat Nov 12 10:47:12 PST 2016


Author: zturner
Date: Sat Nov 12 12:47:11 2016
New Revision: 286728

URL: http://llvm.org/viewvc/llvm-project?rev=286728&view=rev
Log:
Make CommandReturnObject methods accept StringRefs.

Modified:
    lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h
    lldb/trunk/source/Interpreter/CommandReturnObject.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h?rev=286728&r1=286727&r2=286728&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandReturnObject.h Sat Nov 12 12:47:11 2016
@@ -91,28 +91,28 @@ public:
 
   void Clear();
 
-  void AppendMessage(const char *in_string);
+  void AppendMessage(llvm::StringRef in_string);
 
   void AppendMessageWithFormat(const char *format, ...)
       __attribute__((format(printf, 2, 3)));
 
-  void AppendRawWarning(const char *in_string);
+  void AppendRawWarning(llvm::StringRef in_string);
 
-  void AppendWarning(const char *in_string);
+  void AppendWarning(llvm::StringRef in_string);
 
   void AppendWarningWithFormat(const char *format, ...)
       __attribute__((format(printf, 2, 3)));
 
-  void AppendError(const char *in_string);
+  void AppendError(llvm::StringRef in_string);
 
-  void AppendRawError(const char *in_string);
+  void AppendRawError(llvm::StringRef in_string);
 
   void AppendErrorWithFormat(const char *format, ...)
       __attribute__((format(printf, 2, 3)));
 
   void SetError(const Error &error, const char *fallback_error_cstr = nullptr);
 
-  void SetError(const char *error_cstr);
+  void SetError(llvm::StringRef error_cstr);
 
   lldb::ReturnStatus GetStatus();
 

Modified: lldb/trunk/source/Interpreter/CommandReturnObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandReturnObject.cpp?rev=286728&r1=286727&r2=286728&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandReturnObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandReturnObject.cpp Sat Nov 12 12:47:11 2016
@@ -84,30 +84,31 @@ void CommandReturnObject::AppendWarningW
   GetErrorStream().Printf("warning: %s", sstrm.GetData());
 }
 
-void CommandReturnObject::AppendMessage(const char *in_string) {
-  if (!in_string)
+void CommandReturnObject::AppendMessage(llvm::StringRef in_string) {
+  if (in_string.empty())
     return;
-  GetOutputStream().Printf("%s\n", in_string);
+  GetOutputStream() << in_string << "\n";
 }
 
-void CommandReturnObject::AppendWarning(const char *in_string) {
-  if (!in_string || *in_string == '\0')
+void CommandReturnObject::AppendWarning(llvm::StringRef in_string) {
+  if (in_string.empty())
     return;
-  GetErrorStream().Printf("warning: %s\n", in_string);
+  GetErrorStream() << "warning: " << in_string << "\n";
 }
 
 // Similar to AppendWarning, but do not prepend 'warning: ' to message, and
 // don't append "\n" to the end of it.
 
-void CommandReturnObject::AppendRawWarning(const char *in_string) {
-  if (in_string && in_string[0])
-    GetErrorStream().PutCString(in_string);
+void CommandReturnObject::AppendRawWarning(llvm::StringRef in_string) {
+  if (in_string.empty())
+    return;
+  GetErrorStream() << in_string;
 }
 
-void CommandReturnObject::AppendError(const char *in_string) {
-  if (!in_string || *in_string == '\0')
+void CommandReturnObject::AppendError(llvm::StringRef in_string) {
+  if (in_string.empty())
     return;
-  GetErrorStream().Printf("error: %s\n", in_string);
+  GetErrorStream() << "error: " << in_string << "\n";
 }
 
 void CommandReturnObject::SetError(const Error &error,
@@ -118,19 +119,21 @@ void CommandReturnObject::SetError(const
   SetError(error_cstr);
 }
 
-void CommandReturnObject::SetError(const char *error_cstr) {
-  if (error_cstr) {
-    AppendError(error_cstr);
-    SetStatus(eReturnStatusFailed);
-  }
+void CommandReturnObject::SetError(llvm::StringRef error_str) {
+  if (error_str.empty())
+    return;
+
+  AppendError(error_str);
+  SetStatus(eReturnStatusFailed);
 }
 
 // Similar to AppendError, but do not prepend 'Error: ' to message, and
 // don't append "\n" to the end of it.
 
-void CommandReturnObject::AppendRawError(const char *in_string) {
-  if (in_string && in_string[0])
-    GetErrorStream().PutCString(in_string);
+void CommandReturnObject::AppendRawError(llvm::StringRef in_string) {
+  if (in_string.empty())
+    return;
+  GetErrorStream() << in_string;
 }
 
 void CommandReturnObject::SetStatus(ReturnStatus status) { m_status = status; }




More information about the lldb-commits mailing list