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 #include "lldb/Interpreter/OptionArgParser.h" 13 #include "lldb/Utility/Stream.h" 14 #include "lldb/Utility/StringList.h" 15 #include "llvm/ADT/STLExtras.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 void OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 21 uint32_t dump_mask) { 22 if (dump_mask & eDumpOptionType) 23 strm.Printf("(%s)", GetTypeAsCString()); 24 25 if (dump_mask & eDumpOptionValue) { 26 if (dump_mask & eDumpOptionType) 27 strm.PutCString(" = "); 28 if (m_current_value != '\0') 29 strm.PutChar(m_current_value); 30 else 31 strm.PutCString("(null)"); 32 } 33 } 34 35 Status OptionValueChar::SetValueFromString(llvm::StringRef value, 36 VarSetOperationType op) { 37 Status error; 38 switch (op) { 39 case eVarSetOperationClear: 40 Clear(); 41 break; 42 43 case eVarSetOperationReplace: 44 case eVarSetOperationAssign: { 45 bool success = false; 46 char char_value = OptionArgParser::ToChar(value, '\0', &success); 47 if (success) { 48 m_current_value = char_value; 49 m_value_was_set = true; 50 } else 51 error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", 52 value.str().c_str()); 53 } break; 54 55 default: 56 error = OptionValue::SetValueFromString(value, op); 57 break; 58 } 59 return error; 60 } 61 62 lldb::OptionValueSP OptionValueChar::DeepCopy() const { 63 return OptionValueSP(new OptionValueChar(*this)); 64 } 65