OptionValueChar.cpp revision 341825
1278332Semaste//===-- OptionValueChar.cpp -------------------------------------*- C++ -*-===// 2278332Semaste// 3278332Semaste// The LLVM Compiler Infrastructure 4278332Semaste// 5278332Semaste// This file is distributed under the University of Illinois Open Source 6278332Semaste// License. See LICENSE.TXT for details. 7278332Semaste// 8278332Semaste//===----------------------------------------------------------------------===// 9278332Semaste 10278332Semaste#include "lldb/Interpreter/OptionValueChar.h" 11278332Semaste 12278332Semaste// C Includes 13278332Semaste// C++ Includes 14278332Semaste// Other libraries and framework includes 15278332Semaste// Project includes 16341825Sdim#include "lldb/Interpreter/OptionArgParser.h" 17321369Sdim#include "lldb/Utility/Stream.h" 18321369Sdim#include "lldb/Utility/StringList.h" 19278332Semaste#include "llvm/ADT/STLExtras.h" 20278332Semaste 21278332Semasteusing namespace lldb; 22278332Semasteusing namespace lldb_private; 23278332Semaste 24314564Sdimvoid OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 25314564Sdim uint32_t dump_mask) { 26314564Sdim if (dump_mask & eDumpOptionType) 27314564Sdim strm.Printf("(%s)", GetTypeAsCString()); 28314564Sdim 29314564Sdim if (dump_mask & eDumpOptionValue) { 30278332Semaste if (dump_mask & eDumpOptionType) 31314564Sdim strm.PutCString(" = "); 32314564Sdim if (m_current_value != '\0') 33314564Sdim strm.PutChar(m_current_value); 34314564Sdim else 35314564Sdim strm.PutCString("(null)"); 36314564Sdim } 37278332Semaste} 38278332Semaste 39321369SdimStatus OptionValueChar::SetValueFromString(llvm::StringRef value, 40321369Sdim VarSetOperationType op) { 41321369Sdim Status error; 42314564Sdim switch (op) { 43314564Sdim case eVarSetOperationClear: 44314564Sdim Clear(); 45314564Sdim break; 46278332Semaste 47314564Sdim case eVarSetOperationReplace: 48314564Sdim case eVarSetOperationAssign: { 49314564Sdim bool success = false; 50341825Sdim char char_value = OptionArgParser::ToChar(value, '\0', &success); 51314564Sdim if (success) { 52314564Sdim m_current_value = char_value; 53314564Sdim m_value_was_set = true; 54314564Sdim } else 55314564Sdim error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", 56314564Sdim value.str().c_str()); 57314564Sdim } break; 58278332Semaste 59314564Sdim default: 60314564Sdim error = OptionValue::SetValueFromString(value, op); 61314564Sdim break; 62314564Sdim } 63314564Sdim return error; 64278332Semaste} 65278332Semaste 66314564Sdimlldb::OptionValueSP OptionValueChar::DeepCopy() const { 67314564Sdim return OptionValueSP(new OptionValueChar(*this)); 68278332Semaste} 69