1 //===-- OptionValueRegex.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/OptionValueRegex.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Stream.h"
19 using namespace lldb_private;
21 void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
23 if (dump_mask & eDumpOptionType)
24 strm.Printf("(%s)", GetTypeAsCString());
25 if (dump_mask & eDumpOptionValue) {
26 if (dump_mask & eDumpOptionType)
27 strm.PutCString(" = ");
28 if (m_regex.IsValid()) {
29 llvm::StringRef regex_text = m_regex.GetText();
30 strm.Printf("%s", regex_text.str().c_str());
35 Error OptionValueRegex::SetValueFromString(llvm::StringRef value,
36 VarSetOperationType op) {
39 case eVarSetOperationInvalid:
40 case eVarSetOperationInsertBefore:
41 case eVarSetOperationInsertAfter:
42 case eVarSetOperationRemove:
43 case eVarSetOperationAppend:
44 error = OptionValue::SetValueFromString(value, op);
47 case eVarSetOperationClear:
52 case eVarSetOperationReplace:
53 case eVarSetOperationAssign:
54 if (m_regex.Compile(value)) {
55 m_value_was_set = true;
58 char regex_error[1024];
59 if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
60 error.SetErrorString(regex_error);
62 error.SetErrorStringWithFormat("regex error %u",
63 m_regex.GetErrorCode());
70 lldb::OptionValueSP OptionValueRegex::DeepCopy() const {
71 return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str()));