1 //===-- OptionValueRegex.cpp ------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Interpreter/OptionValueRegex.h"
11
12 #include "lldb/Utility/Stream.h"
13
14 using namespace lldb;
15 using namespace lldb_private;
16
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)17 void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
18 uint32_t dump_mask) {
19 if (dump_mask & eDumpOptionType)
20 strm.Printf("(%s)", GetTypeAsCString());
21 if (dump_mask & eDumpOptionValue) {
22 if (dump_mask & eDumpOptionType)
23 strm.PutCString(" = ");
24 if (m_regex.IsValid()) {
25 llvm::StringRef regex_text = m_regex.GetText();
26 strm.Printf("%s", regex_text.str().c_str());
27 }
28 }
29 }
30
SetValueFromString(llvm::StringRef value,VarSetOperationType op)31 Status OptionValueRegex::SetValueFromString(llvm::StringRef value,
32 VarSetOperationType op) {
33 Status error;
34 switch (op) {
35 case eVarSetOperationInvalid:
36 case eVarSetOperationInsertBefore:
37 case eVarSetOperationInsertAfter:
38 case eVarSetOperationRemove:
39 case eVarSetOperationAppend:
40 error = OptionValue::SetValueFromString(value, op);
41 break;
42
43 case eVarSetOperationClear:
44 Clear();
45 NotifyValueChanged();
46 break;
47
48 case eVarSetOperationReplace:
49 case eVarSetOperationAssign:
50 if (m_regex.Compile(value)) {
51 m_value_was_set = true;
52 NotifyValueChanged();
53 } else {
54 char regex_error[1024];
55 if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
56 error.SetErrorString(regex_error);
57 else
58 error.SetErrorStringWithFormat("regex error %u",
59 m_regex.GetErrorCode());
60 }
61 break;
62 }
63 return error;
64 }
65
DeepCopy() const66 lldb::OptionValueSP OptionValueRegex::DeepCopy() const {
67 return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str()));
68 }
69