Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/Stream.h" |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 22 | uint32_t dump_mask) { |
| 23 | if (dump_mask & eDumpOptionType) |
| 24 | strm.Printf("(%s)", GetTypeAsCString()); |
| 25 | if (dump_mask & eDumpOptionValue) { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 26 | if (dump_mask & eDumpOptionType) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | strm.PutCString(" = "); |
| 28 | if (m_regex.IsValid()) { |
| 29 | const char *regex_text = m_regex.GetText(); |
| 30 | if (regex_text && regex_text[0]) |
| 31 | strm.Printf("%s", regex_text); |
| 32 | } else { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 33 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | Error OptionValueRegex::SetValueFromString(llvm::StringRef value, |
| 38 | VarSetOperationType op) { |
| 39 | Error error; |
| 40 | switch (op) { |
| 41 | case eVarSetOperationInvalid: |
| 42 | case eVarSetOperationInsertBefore: |
| 43 | case eVarSetOperationInsertAfter: |
| 44 | case eVarSetOperationRemove: |
| 45 | case eVarSetOperationAppend: |
| 46 | error = OptionValue::SetValueFromString(value, op); |
| 47 | break; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | case eVarSetOperationClear: |
| 50 | Clear(); |
| 51 | NotifyValueChanged(); |
| 52 | break; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | case eVarSetOperationReplace: |
| 55 | case eVarSetOperationAssign: |
| 56 | if (m_regex.Compile(value.str().c_str())) { |
| 57 | m_value_was_set = true; |
| 58 | NotifyValueChanged(); |
| 59 | } else { |
| 60 | char regex_error[1024]; |
| 61 | if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error))) |
| 62 | error.SetErrorString(regex_error); |
| 63 | else |
| 64 | error.SetErrorStringWithFormat("regex error %u", |
| 65 | m_regex.GetErrorCode()); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 66 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | break; |
| 68 | } |
| 69 | return error; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | lldb::OptionValueSP OptionValueRegex::DeepCopy() const { |
| 73 | return OptionValueSP(new OptionValueRegex(m_regex.GetText())); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 74 | } |