blob: b5ef1d346aea5c8a05409b65c63172a6255f235b [file] [log] [blame]
Zachary Turner3e7442b2015-01-12 20:44:02 +00001//===-- 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
21using namespace lldb;
22using namespace lldb_private;
23
24void
25OptionValueChar::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
41Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000042OptionValueChar::SetValueFromString (llvm::StringRef value,
Zachary Turner3e7442b2015-01-12 20:44:02 +000043 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;
Pavel Labathc95f7e22015-02-20 11:14:59 +000056 char char_value = Args::StringToChar(value.str().c_str(), '\0', &success);
Zachary Turner3e7442b2015-01-12 20:44:02 +000057 if (success)
58 {
59 m_current_value = char_value;
60 m_value_was_set = true;
61 }
62 else
Pavel Labathc95f7e22015-02-20 11:14:59 +000063 error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", value.str().c_str());
Zachary Turner3e7442b2015-01-12 20:44:02 +000064 }
65 break;
66
67 default:
Pavel Labathc95f7e22015-02-20 11:14:59 +000068 error = OptionValue::SetValueFromString (value.str().c_str(), op);
Zachary Turner3e7442b2015-01-12 20:44:02 +000069 break;
70 }
71 return error;
72}
73
74lldb::OptionValueSP
75OptionValueChar::DeepCopy () const
76{
77 return OptionValueSP(new OptionValueChar(*this));
78}
79
80