1 //===-- OptionValueString.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/OptionValueString.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Stream.h" 17 #include "lldb/Interpreter/Args.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 void 23 OptionValueString::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 24 { 25 if (dump_mask & eDumpOptionType) 26 strm.Printf ("(%s)", GetTypeAsCString ()); 27 if (dump_mask & eDumpOptionValue) 28 { 29 if (dump_mask & eDumpOptionType) 30 strm.PutCString (" = "); 31 if (!m_current_value.empty() || m_value_was_set) 32 { 33 if (m_options.Test (eOptionEncodeCharacterEscapeSequences)) 34 { 35 std::string expanded_escape_value; 36 Args::ExpandEscapedCharacters(m_current_value.c_str(), expanded_escape_value); 37 if (dump_mask & eDumpOptionRaw) 38 strm.Printf ("%s", expanded_escape_value.c_str()); 39 else 40 strm.Printf ("\"%s\"", expanded_escape_value.c_str()); 41 } 42 else 43 { 44 if (dump_mask & eDumpOptionRaw) 45 strm.Printf ("%s", m_current_value.c_str()); 46 else 47 strm.Printf ("\"%s\"", m_current_value.c_str()); 48 } 49 } 50 } 51 } 52 53 Error 54 OptionValueString::SetValueFromCString (const char *value_cstr, 55 VarSetOperationType op) 56 { 57 Error error; 58 switch (op) 59 { 60 case eVarSetOperationInvalid: 61 case eVarSetOperationInsertBefore: 62 case eVarSetOperationInsertAfter: 63 case eVarSetOperationRemove: 64 error = OptionValue::SetValueFromCString (value_cstr, op); 65 break; 66 67 case eVarSetOperationAppend: 68 if (value_cstr && value_cstr[0]) 69 { 70 if (m_options.Test (eOptionEncodeCharacterEscapeSequences)) 71 { 72 std::string str; 73 Args::EncodeEscapeSequences (value_cstr, str); 74 m_current_value += str; 75 } 76 else 77 m_current_value += value_cstr; 78 } 79 break; 80 81 case eVarSetOperationClear: 82 Clear (); 83 break; 84 85 case eVarSetOperationReplace: 86 case eVarSetOperationAssign: 87 m_value_was_set = true; 88 if (m_options.Test (eOptionEncodeCharacterEscapeSequences)) 89 { 90 Args::EncodeEscapeSequences (value_cstr, m_current_value); 91 } 92 else 93 { 94 SetCurrentValue (value_cstr); 95 } 96 break; 97 } 98 return error; 99 } 100 101 102 lldb::OptionValueSP 103 OptionValueString::DeepCopy () const 104 { 105 return OptionValueSP(new OptionValueString(*this)); 106 } 107