1 | //===-- OptionValueRegex.cpp ----------------------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "lldb/Interpreter/OptionValueRegex.h" |
10 | |
11 | #include "lldb/Utility/Stream.h" |
12 | |
13 | using namespace lldb; |
14 | using namespace lldb_private; |
15 | |
16 | void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
17 | uint32_t dump_mask) { |
18 | if (dump_mask & eDumpOptionType) |
19 | strm.Printf(format: "(%s)", GetTypeAsCString()); |
20 | if (dump_mask & eDumpOptionValue) { |
21 | if (dump_mask & eDumpOptionType) |
22 | strm.PutCString(cstr: " = "); |
23 | if (m_regex.IsValid()) { |
24 | llvm::StringRef regex_text = m_regex.GetText(); |
25 | strm.Printf(format: "%s", regex_text.str().c_str()); |
26 | } |
27 | } |
28 | } |
29 | |
30 | Status OptionValueRegex::SetValueFromString(llvm::StringRef value, |
31 | VarSetOperationType op) { |
32 | Status error; |
33 | switch (op) { |
34 | case eVarSetOperationInvalid: |
35 | case eVarSetOperationInsertBefore: |
36 | case eVarSetOperationInsertAfter: |
37 | case eVarSetOperationRemove: |
38 | case eVarSetOperationAppend: |
39 | error = OptionValue::SetValueFromString(value, op); |
40 | break; |
41 | |
42 | case eVarSetOperationClear: |
43 | Clear(); |
44 | NotifyValueChanged(); |
45 | break; |
46 | |
47 | case eVarSetOperationReplace: |
48 | case eVarSetOperationAssign: |
49 | m_regex = RegularExpression(value); |
50 | if (m_regex.IsValid()) { |
51 | m_value_was_set = true; |
52 | NotifyValueChanged(); |
53 | } else if (llvm::Error err = m_regex.GetError()) { |
54 | error.SetErrorString(llvm::toString(E: std::move(err))); |
55 | } else { |
56 | error.SetErrorString("regex error"); |
57 | } |
58 | break; |
59 | } |
60 | return error; |
61 | } |
62 |