1 //===-- OptionValueBoolean.cpp ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionValueBoolean.h"
14 // Other libraries and framework 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"
22 using namespace lldb_private;
25 OptionValueBoolean::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
27 if (dump_mask & eDumpOptionType)
28 strm.Printf ("(%s)", GetTypeAsCString ());
29 // if (dump_mask & eDumpOptionName)
30 // DumpQualifiedName (strm);
31 if (dump_mask & eDumpOptionValue)
33 if (dump_mask & eDumpOptionType)
34 strm.PutCString (" = ");
35 strm.PutCString (m_current_value ? "true" : "false");
40 OptionValueBoolean::SetValueFromCString (const char *value_cstr,
41 VarSetOperationType op)
46 case eVarSetOperationClear:
51 case eVarSetOperationReplace:
52 case eVarSetOperationAssign:
55 bool value = Args::StringToBoolean(value_cstr, false, &success);
58 m_value_was_set = true;
59 m_current_value = value;
64 if (value_cstr == nullptr)
65 error.SetErrorString ("invalid boolean string value: NULL");
66 else if (value_cstr[0] == '\0')
67 error.SetErrorString ("invalid boolean string value <empty>");
69 error.SetErrorStringWithFormat ("invalid boolean string value: '%s'", value_cstr);
74 case eVarSetOperationInsertBefore:
75 case eVarSetOperationInsertAfter:
76 case eVarSetOperationRemove:
77 case eVarSetOperationAppend:
78 case eVarSetOperationInvalid:
79 error = OptionValue::SetValueFromCString (value_cstr, op);
86 OptionValueBoolean::DeepCopy () const
88 return OptionValueSP(new OptionValueBoolean(*this));
92 OptionValueBoolean::AutoComplete (CommandInterpreter &interpreter,
94 int match_start_point,
95 int max_return_elements,
99 word_complete = false;
105 static const StringEntry g_autocomplete_entries[] =
116 const size_t k_num_autocomplete_entries = llvm::array_lengthof(g_autocomplete_entries);
120 const size_t s_len = strlen(s);
121 for (size_t i=0; i<k_num_autocomplete_entries; ++i)
123 if (s_len <= g_autocomplete_entries[i].length)
124 if (::strncasecmp(s, g_autocomplete_entries[i].string, s_len) == 0)
125 matches.AppendString(g_autocomplete_entries[i].string);
130 // only suggest "true" or "false" by default
131 for (size_t i=0; i<2; ++i)
132 matches.AppendString(g_autocomplete_entries[i].string);
134 return matches.GetSize();