1278332Semaste//===-- OptionValueChar.cpp -------------------------------------*- C++ -*-===// 2278332Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6278332Semaste// 7278332Semaste//===----------------------------------------------------------------------===// 8278332Semaste 9278332Semaste#include "lldb/Interpreter/OptionValueChar.h" 10278332Semaste 11341825Sdim#include "lldb/Interpreter/OptionArgParser.h" 12321369Sdim#include "lldb/Utility/Stream.h" 13321369Sdim#include "lldb/Utility/StringList.h" 14278332Semaste#include "llvm/ADT/STLExtras.h" 15278332Semaste 16278332Semasteusing namespace lldb; 17278332Semasteusing namespace lldb_private; 18278332Semaste 19314564Sdimvoid OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 20314564Sdim uint32_t dump_mask) { 21314564Sdim if (dump_mask & eDumpOptionType) 22314564Sdim strm.Printf("(%s)", GetTypeAsCString()); 23314564Sdim 24314564Sdim if (dump_mask & eDumpOptionValue) { 25278332Semaste if (dump_mask & eDumpOptionType) 26314564Sdim strm.PutCString(" = "); 27314564Sdim if (m_current_value != '\0') 28314564Sdim strm.PutChar(m_current_value); 29314564Sdim else 30314564Sdim strm.PutCString("(null)"); 31314564Sdim } 32278332Semaste} 33278332Semaste 34321369SdimStatus OptionValueChar::SetValueFromString(llvm::StringRef value, 35321369Sdim VarSetOperationType op) { 36321369Sdim Status error; 37314564Sdim switch (op) { 38314564Sdim case eVarSetOperationClear: 39314564Sdim Clear(); 40314564Sdim break; 41278332Semaste 42314564Sdim case eVarSetOperationReplace: 43314564Sdim case eVarSetOperationAssign: { 44314564Sdim bool success = false; 45341825Sdim char char_value = OptionArgParser::ToChar(value, '\0', &success); 46314564Sdim if (success) { 47314564Sdim m_current_value = char_value; 48314564Sdim m_value_was_set = true; 49314564Sdim } else 50314564Sdim error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", 51314564Sdim value.str().c_str()); 52314564Sdim } break; 53278332Semaste 54314564Sdim default: 55314564Sdim error = OptionValue::SetValueFromString(value, op); 56314564Sdim break; 57314564Sdim } 58314564Sdim return error; 59278332Semaste} 60278332Semaste 61314564Sdimlldb::OptionValueSP OptionValueChar::DeepCopy() const { 62314564Sdim return OptionValueSP(new OptionValueChar(*this)); 63278332Semaste} 64