2020-01-24 08:23:27 +01:00
|
|
|
//===-- OptionValueRegex.cpp ----------------------------------------------===//
|
2012-08-22 17:17:09 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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-22 17:17:09 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionValueRegex.h"
|
|
|
|
|
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2012-08-22 17:17:09 +00:00
|
|
|
|
|
|
|
|
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()) {
|
2016-09-21 16:01:28 +00:00
|
|
|
llvm::StringRef regex_text = m_regex.GetText();
|
|
|
|
|
strm.Printf("%s", regex_text.str().c_str());
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status OptionValueRegex::SetValueFromString(llvm::StringRef value,
|
|
|
|
|
VarSetOperationType op) {
|
|
|
|
|
Status error;
|
2012-08-22 17:17:09 +00:00
|
|
|
switch (op) {
|
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
|
case eVarSetOperationRemove:
|
|
|
|
|
case eVarSetOperationAppend:
|
2015-02-20 11:14:59 +00:00
|
|
|
error = OptionValue::SetValueFromString(value, op);
|
2012-08-22 17:17:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case eVarSetOperationClear:
|
|
|
|
|
Clear();
|
2015-01-13 21:13:08 +00:00
|
|
|
NotifyValueChanged();
|
2012-08-22 17:17:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case eVarSetOperationReplace:
|
|
|
|
|
case eVarSetOperationAssign:
|
2019-08-20 09:24:20 +00:00
|
|
|
m_regex = RegularExpression(value);
|
|
|
|
|
if (m_regex.IsValid()) {
|
2012-08-22 17:17:09 +00:00
|
|
|
m_value_was_set = true;
|
2015-01-13 21:13:08 +00:00
|
|
|
NotifyValueChanged();
|
2019-08-16 21:25:36 +00:00
|
|
|
} else if (llvm::Error err = m_regex.GetError()) {
|
|
|
|
|
error.SetErrorString(llvm::toString(std::move(err)));
|
2012-08-22 17:17:09 +00:00
|
|
|
} else {
|
2019-08-16 21:25:36 +00:00
|
|
|
error.SetErrorString("regex error");
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lldb::OptionValueSP OptionValueRegex::DeepCopy() const {
|
2016-09-21 16:01:28 +00:00
|
|
|
return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str()));
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|