blob: 696e62b78e7a044d0e1a991f97b9b33de83a7cda [file] [log] [blame]
Greg Clayton73844aa2012-08-22 17:17:09 +00001//===-- OptionValueString.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/OptionValueString.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Stream.h"
Greg Clayton3b1afc62012-09-01 00:38:36 +000017#include "lldb/Interpreter/Args.h"
Greg Clayton73844aa2012-08-22 17:17:09 +000018
19using namespace lldb;
20using namespace lldb_private;
21
22void
23OptionValueString::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
24{
25 if (dump_mask & eDumpOptionType)
26 strm.Printf ("(%s)", GetTypeAsCString ());
27 if (dump_mask & eDumpOptionValue)
28 {
29 if (dump_mask & eDumpOptionType)
30 strm.PutCString (" = ");
31 if (!m_current_value.empty() || m_value_was_set)
32 {
Greg Clayton3b1afc62012-09-01 00:38:36 +000033 if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
34 {
35 std::string expanded_escape_value;
36 Args::ExpandEscapedCharacters(m_current_value.c_str(), expanded_escape_value);
37 if (dump_mask & eDumpOptionRaw)
38 strm.Printf ("%s", expanded_escape_value.c_str());
39 else
40 strm.Printf ("\"%s\"", expanded_escape_value.c_str());
41 }
Greg Clayton73844aa2012-08-22 17:17:09 +000042 else
Greg Clayton3b1afc62012-09-01 00:38:36 +000043 {
44 if (dump_mask & eDumpOptionRaw)
45 strm.Printf ("%s", m_current_value.c_str());
46 else
47 strm.Printf ("\"%s\"", m_current_value.c_str());
48 }
Greg Clayton73844aa2012-08-22 17:17:09 +000049 }
50 }
51}
52
53Error
54OptionValueString::SetValueFromCString (const char *value_cstr,
55 VarSetOperationType op)
56{
57 Error error;
58 switch (op)
59 {
60 case eVarSetOperationInvalid:
61 case eVarSetOperationInsertBefore:
62 case eVarSetOperationInsertAfter:
63 case eVarSetOperationRemove:
64 error = OptionValue::SetValueFromCString (value_cstr, op);
65 break;
66
67 case eVarSetOperationAppend:
68 if (value_cstr && value_cstr[0])
Greg Clayton3b1afc62012-09-01 00:38:36 +000069 {
70 if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
71 {
72 std::string str;
73 Args::EncodeEscapeSequences (value_cstr, str);
74 m_current_value += str;
75 }
76 else
77 m_current_value += value_cstr;
78 }
Greg Clayton73844aa2012-08-22 17:17:09 +000079 break;
80
81 case eVarSetOperationClear:
82 Clear ();
83 break;
84
85 case eVarSetOperationReplace:
86 case eVarSetOperationAssign:
87 m_value_was_set = true;
Greg Clayton3b1afc62012-09-01 00:38:36 +000088 if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
89 {
90 Args::EncodeEscapeSequences (value_cstr, m_current_value);
91 }
92 else
93 {
94 SetCurrentValue (value_cstr);
95 }
Greg Clayton73844aa2012-08-22 17:17:09 +000096 break;
97 }
98 return error;
99}
100
101
102lldb::OptionValueSP
103OptionValueString::DeepCopy () const
104{
105 return OptionValueSP(new OptionValueString(*this));
106}