blob: ebe7ae2feb91a05e401b0c06215f040968dcd681 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Stream.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21void
22OptionValueRegex::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
23{
24 if (dump_mask & eDumpOptionType)
25 strm.Printf ("(%s)", GetTypeAsCString ());
26 if (dump_mask & eDumpOptionValue)
27 {
28 if (dump_mask & eDumpOptionType)
29 strm.PutCString (" = ");
30 if (m_regex.IsValid())
31 {
32 const char *regex_text = m_regex.GetText();
33 if (regex_text && regex_text[0])
34 strm.Printf ("%s", regex_text);
35 }
36 else
37 {
38
39 }
40 }
41}
42
43Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000044OptionValueRegex::SetValueFromString (llvm::StringRef value,
Greg Clayton67cc0632012-08-22 17:17:09 +000045 VarSetOperationType op)
46{
47 Error error;
48 switch (op)
49 {
50 case eVarSetOperationInvalid:
51 case eVarSetOperationInsertBefore:
52 case eVarSetOperationInsertAfter:
53 case eVarSetOperationRemove:
54 case eVarSetOperationAppend:
Pavel Labathc95f7e22015-02-20 11:14:59 +000055 error = OptionValue::SetValueFromString (value, op);
Greg Clayton67cc0632012-08-22 17:17:09 +000056 break;
57
58 case eVarSetOperationClear:
59 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000060 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000061 break;
62
63 case eVarSetOperationReplace:
64 case eVarSetOperationAssign:
Pavel Labathc95f7e22015-02-20 11:14:59 +000065 if (m_regex.Compile (value.str().c_str()))
Greg Clayton67cc0632012-08-22 17:17:09 +000066 {
67 m_value_was_set = true;
Greg Clayton332e8b12015-01-13 21:13:08 +000068 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000069 }
70 else
71 {
72 char regex_error[1024];
73 if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
74 error.SetErrorString (regex_error);
75 else
76 error.SetErrorStringWithFormat ("regex error %u", m_regex.GetErrorCode());
77 }
78 break;
79 }
80 return error;
81}
82
83
84lldb::OptionValueSP
85OptionValueRegex::DeepCopy () const
86{
Greg Clayton7bd4c602015-01-21 21:51:02 +000087 return OptionValueSP(new OptionValueRegex(m_regex.GetText()));
Greg Clayton67cc0632012-08-22 17:17:09 +000088}