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 21 void 22 OptionValueRegex::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 43 Error 44 OptionValueRegex::SetValueFromString (llvm::StringRef value, 45 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: 55 error = OptionValue::SetValueFromString (value, op); 56 break; 57 58 case eVarSetOperationClear: 59 Clear(); 60 NotifyValueChanged(); 61 break; 62 63 case eVarSetOperationReplace: 64 case eVarSetOperationAssign: 65 if (m_regex.Compile (value.str().c_str())) 66 { 67 m_value_was_set = true; 68 NotifyValueChanged(); 69 } 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 84 lldb::OptionValueSP 85 OptionValueRegex::DeepCopy () const 86 { 87 return OptionValueSP(new OptionValueRegex(m_regex.GetText())); 88 } 89