1 //===-- OptionValueChar.cpp -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionValueChar.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Stream.h" 17 #include "lldb/Core/StringList.h" 18 #include "lldb/Interpreter/Args.h" 19 #include "llvm/ADT/STLExtras.h" 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 void 25 OptionValueChar::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 26 { 27 if (dump_mask & eDumpOptionType) 28 strm.Printf ("(%s)", GetTypeAsCString ()); 29 30 if (dump_mask & eDumpOptionValue) 31 { 32 if (dump_mask & eDumpOptionType) 33 strm.PutCString (" = "); 34 if (m_current_value != '\0') 35 strm.PutChar(m_current_value); 36 else 37 strm.PutCString("(null)"); 38 } 39 } 40 41 Error 42 OptionValueChar::SetValueFromString (llvm::StringRef value, 43 VarSetOperationType op) 44 { 45 Error error; 46 switch (op) 47 { 48 case eVarSetOperationClear: 49 Clear(); 50 break; 51 52 case eVarSetOperationReplace: 53 case eVarSetOperationAssign: 54 { 55 bool success = false; 56 char char_value = Args::StringToChar(value.str().c_str(), '\0', &success); 57 if (success) 58 { 59 m_current_value = char_value; 60 m_value_was_set = true; 61 } 62 else 63 error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", value.str().c_str()); 64 } 65 break; 66 67 default: 68 error = OptionValue::SetValueFromString (value.str().c_str(), op); 69 break; 70 } 71 return error; 72 } 73 74 lldb::OptionValueSP 75 OptionValueChar::DeepCopy () const 76 { 77 return OptionValueSP(new OptionValueChar(*this)); 78 } 79 80 81