
Adds a `--defaults`/`-d` flag to `settings show`. This mode will _optionally_ show a setting's default value. In other words, this does not always print a default value for every setting. A default value is not shown when the current value _is_ the default. Note: some setting types do not print empty or invalid values. For these setting types, if the default value is empty or invalid, the same elision logic is applied to printing the default value.
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
//===-- OptionValueRegex.cpp ----------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Interpreter/OptionValueRegex.h"
|
|
|
|
#include "lldb/Interpreter/OptionValue.h"
|
|
#include "lldb/Utility/Stream.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
|
|
uint32_t dump_mask) {
|
|
if (dump_mask & eDumpOptionType)
|
|
strm.Printf("(%s)", GetTypeAsCString());
|
|
if (dump_mask & eDumpOptionValue) {
|
|
if (dump_mask & eDumpOptionType)
|
|
strm.PutCString(" = ");
|
|
if (m_regex.IsValid()) {
|
|
llvm::StringRef regex_text = m_regex.GetText();
|
|
strm.Printf("%s", regex_text.str().c_str());
|
|
}
|
|
if (dump_mask & eDumpOptionDefaultValue &&
|
|
m_regex.GetText() != m_default_regex_str &&
|
|
!m_default_regex_str.empty()) {
|
|
DefaultValueFormat label(strm);
|
|
strm.PutCString(m_default_regex_str);
|
|
}
|
|
}
|
|
}
|
|
|
|
Status OptionValueRegex::SetValueFromString(llvm::StringRef value,
|
|
VarSetOperationType op) {
|
|
Status error;
|
|
switch (op) {
|
|
case eVarSetOperationInvalid:
|
|
case eVarSetOperationInsertBefore:
|
|
case eVarSetOperationInsertAfter:
|
|
case eVarSetOperationRemove:
|
|
case eVarSetOperationAppend:
|
|
error = OptionValue::SetValueFromString(value, op);
|
|
break;
|
|
|
|
case eVarSetOperationClear:
|
|
Clear();
|
|
NotifyValueChanged();
|
|
break;
|
|
|
|
case eVarSetOperationReplace:
|
|
case eVarSetOperationAssign:
|
|
m_regex = RegularExpression(value);
|
|
if (m_regex.IsValid()) {
|
|
m_value_was_set = true;
|
|
NotifyValueChanged();
|
|
} else if (llvm::Error err = m_regex.GetError()) {
|
|
return Status::FromError(std::move(err));
|
|
} else {
|
|
return Status::FromErrorString("regex error");
|
|
}
|
|
break;
|
|
}
|
|
return error;
|
|
}
|