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/Host/PosixApi.h"
17 #include "lldb/Interpreter/Args.h"
18 #include "lldb/Utility/Stream.h"
19 #include "lldb/Utility/StringList.h"
20 #include "llvm/ADT/STLExtras.h"
23 using namespace lldb_private;
25 void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,
26 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) {
32 if (dump_mask & eDumpOptionType)
33 strm.PutCString(" = ");
34 strm.PutCString(m_current_value ? "true" : "false");
38 Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,
39 VarSetOperationType op) {
42 case eVarSetOperationClear:
47 case eVarSetOperationReplace:
48 case eVarSetOperationAssign: {
50 bool value = Args::StringToBoolean(value_str, false, &success);
52 m_value_was_set = true;
53 m_current_value = value;
56 if (value_str.size() == 0)
57 error.SetErrorString("invalid boolean string value <empty>");
59 error.SetErrorStringWithFormat("invalid boolean string value: '%s'",
60 value_str.str().c_str());
64 case eVarSetOperationInsertBefore:
65 case eVarSetOperationInsertAfter:
66 case eVarSetOperationRemove:
67 case eVarSetOperationAppend:
68 case eVarSetOperationInvalid:
69 error = OptionValue::SetValueFromString(value_str, op);
75 lldb::OptionValueSP OptionValueBoolean::DeepCopy() const {
76 return OptionValueSP(new OptionValueBoolean(*this));
79 size_t OptionValueBoolean::AutoComplete(
80 CommandInterpreter &interpreter, llvm::StringRef s, int match_start_point,
81 int max_return_elements, bool &word_complete, StringList &matches) {
82 word_complete = false;
84 static const llvm::StringRef g_autocomplete_entries[] = {
85 "true", "false", "on", "off", "yes", "no", "1", "0"};
87 auto entries = llvm::makeArrayRef(g_autocomplete_entries);
89 // only suggest "true" or "false" by default
91 entries = entries.take_front(2);
93 for (auto entry : entries) {
94 if (entry.startswith_lower(s))
95 matches.AppendString(entry);
97 return matches.GetSize();