OptionValueChar.cpp revision 314564
1139743Simp//===-- OptionValueChar.cpp -------------------------------------*- C++ -*-===// 265577Sdes// 365577Sdes// The LLVM Compiler Infrastructure 459412Smsmith// 559412Smsmith// This file is distributed under the University of Illinois Open Source 659412Smsmith// License. See LICENSE.TXT for details. 759412Smsmith// 859412Smsmith//===----------------------------------------------------------------------===// 959412Smsmith 1059412Smsmith#include "lldb/Interpreter/OptionValueChar.h" 1159412Smsmith 1259412Smsmith// C Includes 1359412Smsmith// C++ Includes 1459412Smsmith// Other libraries and framework includes 1559412Smsmith// Project includes 1659412Smsmith#include "lldb/Core/Stream.h" 1759412Smsmith#include "lldb/Core/StringList.h" 1859412Smsmith#include "lldb/Interpreter/Args.h" 1959412Smsmith#include "llvm/ADT/STLExtras.h" 2059412Smsmith 2159412Smsmithusing namespace lldb; 2259412Smsmithusing namespace lldb_private; 2359412Smsmith 2459412Smsmithvoid OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 2559412Smsmith uint32_t dump_mask) { 2659412Smsmith if (dump_mask & eDumpOptionType) 2759412Smsmith strm.Printf("(%s)", GetTypeAsCString()); 2859412Smsmith 2959412Smsmith if (dump_mask & eDumpOptionValue) { 3059412Smsmith if (dump_mask & eDumpOptionType) 3159412Smsmith strm.PutCString(" = "); 3259412Smsmith if (m_current_value != '\0') 3359412Smsmith strm.PutChar(m_current_value); 3459412Smsmith else 3559412Smsmith strm.PutCString("(null)"); 3659412Smsmith } 3759412Smsmith} 3859412Smsmith 3959412SmsmithError OptionValueChar::SetValueFromString(llvm::StringRef value, 4059412Smsmith VarSetOperationType op) { 4159412Smsmith Error error; 42116173Sobrien switch (op) { 43116173Sobrien case eVarSetOperationClear: 44116173Sobrien Clear(); 4559412Smsmith break; 4683926Sdes 4776166Smarkm case eVarSetOperationReplace: 4874135Sjlemon case eVarSetOperationAssign: { 4983926Sdes bool success = false; 50119911Sdes char char_value = Args::StringToChar(value, '\0', &success); 5176166Smarkm if (success) { 5265633Sdes m_current_value = char_value; 5383926Sdes m_value_was_set = true; 5476166Smarkm } else 5574135Sjlemon error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", 5678025Sdes value.str().c_str()); 5776827Salfred } break; 5885289Sdes 5965633Sdes default: 6065633Sdes error = OptionValue::SetValueFromString(value, op); 6169995Sdes break; 62123246Sdes } 6383926Sdes return error; 6476839Sjlemon} 6583926Sdes 66159995Snetchildlldb::OptionValueSP OptionValueChar::DeepCopy() const { 6765633Sdes return OptionValueSP(new OptionValueChar(*this)); 6883926Sdes} 6983926Sdes