2012-08-23 01:17:09 +08:00
|
|
|
//===-- OptionValueRegex.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2012-08-23 01:17:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionValueRegex.h"
|
|
|
|
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
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) {
|
2012-08-23 01:17:09 +08:00
|
|
|
if (dump_mask & eDumpOptionType)
|
2016-09-07 04:57:50 +08:00
|
|
|
strm.PutCString(" = ");
|
|
|
|
if (m_regex.IsValid()) {
|
2016-09-22 00:01:28 +08:00
|
|
|
llvm::StringRef regex_text = m_regex.GetText();
|
|
|
|
strm.Printf("%s", regex_text.str().c_str());
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValueRegex::SetValueFromString(llvm::StringRef value,
|
|
|
|
VarSetOperationType op) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
switch (op) {
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
case eVarSetOperationRemove:
|
|
|
|
case eVarSetOperationAppend:
|
|
|
|
error = OptionValue::SetValueFromString(value, op);
|
|
|
|
break;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
case eVarSetOperationClear:
|
|
|
|
Clear();
|
|
|
|
NotifyValueChanged();
|
|
|
|
break;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
case eVarSetOperationReplace:
|
|
|
|
case eVarSetOperationAssign:
|
2016-09-22 00:01:28 +08:00
|
|
|
if (m_regex.Compile(value)) {
|
2016-09-07 04:57:50 +08:00
|
|
|
m_value_was_set = true;
|
|
|
|
NotifyValueChanged();
|
|
|
|
} else {
|
|
|
|
char regex_error[1024];
|
|
|
|
if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
|
|
|
|
error.SetErrorString(regex_error);
|
|
|
|
else
|
|
|
|
error.SetErrorStringWithFormat("regex error %u",
|
|
|
|
m_regex.GetErrorCode());
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::OptionValueSP OptionValueRegex::DeepCopy() const {
|
2016-09-22 00:01:28 +08:00
|
|
|
return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str()));
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|