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 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) { 26 if (dump_mask & eDumpOptionType) 27 strm.PutCString(" = "); 28 if (m_regex.IsValid()) { 29 llvm::StringRef regex_text = m_regex.GetText(); 30 strm.Printf("%s", regex_text.str().c_str()); 31 } 32 } 33 } 34 35 Error OptionValueRegex::SetValueFromString(llvm::StringRef value, 36 VarSetOperationType op) { 37 Error error; 38 switch (op) { 39 case eVarSetOperationInvalid: 40 case eVarSetOperationInsertBefore: 41 case eVarSetOperationInsertAfter: 42 case eVarSetOperationRemove: 43 case eVarSetOperationAppend: 44 error = OptionValue::SetValueFromString(value, op); 45 break; 46 47 case eVarSetOperationClear: 48 Clear(); 49 NotifyValueChanged(); 50 break; 51 52 case eVarSetOperationReplace: 53 case eVarSetOperationAssign: 54 if (m_regex.Compile(value)) { 55 m_value_was_set = true; 56 NotifyValueChanged(); 57 } else { 58 char regex_error[1024]; 59 if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error))) 60 error.SetErrorString(regex_error); 61 else 62 error.SetErrorStringWithFormat("regex error %u", 63 m_regex.GetErrorCode()); 64 } 65 break; 66 } 67 return error; 68 } 69 70 lldb::OptionValueSP OptionValueRegex::DeepCopy() const { 71 return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str())); 72 } 73