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"
21 using namespace lldb_private;
24 OptionValueBoolean::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
26 if (dump_mask & eDumpOptionType)
27 strm.Printf ("(%s)", GetTypeAsCString ());
28 // if (dump_mask & eDumpOptionName)
29 // DumpQualifiedName (strm);
30 if (dump_mask & eDumpOptionValue)
32 if (dump_mask & eDumpOptionType)
33 strm.PutCString (" = ");
34 strm.PutCString (m_current_value ? "true" : "false");
39 OptionValueBoolean::SetValueFromCString (const char *value_cstr,
40 VarSetOperationType op)
45 case eVarSetOperationClear:
49 case eVarSetOperationReplace:
50 case eVarSetOperationAssign:
53 bool value = Args::StringToBoolean(value_cstr, false, &success);
56 m_value_was_set = true;
57 m_current_value = value;
61 if (value_cstr == NULL)
62 error.SetErrorString ("invalid boolean string value: NULL");
63 else if (value_cstr[0] == '\0')
64 error.SetErrorString ("invalid boolean string value <empty>");
66 error.SetErrorStringWithFormat ("invalid boolean string value: '%s'", value_cstr);
71 case eVarSetOperationInsertBefore:
72 case eVarSetOperationInsertAfter:
73 case eVarSetOperationRemove:
74 case eVarSetOperationAppend:
75 case eVarSetOperationInvalid:
76 error = OptionValue::SetValueFromCString (value_cstr, op);
83 OptionValueBoolean::DeepCopy () const
85 return OptionValueSP(new OptionValueBoolean(*this));
89 OptionValueBoolean::AutoComplete (CommandInterpreter &interpreter,
91 int match_start_point,
92 int max_return_elements,
96 word_complete = false;
102 static const StringEntry g_autocomplete_entries[] =
113 const size_t k_num_autocomplete_entries = sizeof(g_autocomplete_entries)/sizeof(StringEntry);
117 const size_t s_len = strlen(s);
118 for (size_t i=0; i<k_num_autocomplete_entries; ++i)
120 if (s_len <= g_autocomplete_entries[i].length)
121 if (::strncasecmp(s, g_autocomplete_entries[i].string, s_len) == 0)
122 matches.AppendString(g_autocomplete_entries[i].string);
127 // only suggest "true" or "false" by default
128 for (size_t i=0; i<2; ++i)
129 matches.AppendString(g_autocomplete_entries[i].string);
131 return matches.GetSize();