Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame^] | 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 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | void |
| 22 | OptionValueString::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_current_value.empty() || m_value_was_set) |
| 31 | { |
| 32 | if (dump_mask & eDumpOptionRaw) |
| 33 | strm.Printf ("%s", m_current_value.c_str()); |
| 34 | else |
| 35 | strm.Printf ("\"%s\"", m_current_value.c_str()); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | Error |
| 41 | OptionValueString::SetValueFromCString (const char *value_cstr, |
| 42 | VarSetOperationType op) |
| 43 | { |
| 44 | Error error; |
| 45 | switch (op) |
| 46 | { |
| 47 | case eVarSetOperationInvalid: |
| 48 | case eVarSetOperationInsertBefore: |
| 49 | case eVarSetOperationInsertAfter: |
| 50 | case eVarSetOperationRemove: |
| 51 | error = OptionValue::SetValueFromCString (value_cstr, op); |
| 52 | break; |
| 53 | |
| 54 | case eVarSetOperationAppend: |
| 55 | if (value_cstr && value_cstr[0]) |
| 56 | m_current_value += value_cstr; |
| 57 | break; |
| 58 | |
| 59 | case eVarSetOperationClear: |
| 60 | Clear (); |
| 61 | break; |
| 62 | |
| 63 | case eVarSetOperationReplace: |
| 64 | case eVarSetOperationAssign: |
| 65 | m_value_was_set = true; |
| 66 | SetCurrentValue (value_cstr); |
| 67 | break; |
| 68 | } |
| 69 | return error; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | lldb::OptionValueSP |
| 74 | OptionValueString::DeepCopy () const |
| 75 | { |
| 76 | return OptionValueSP(new OptionValueString(*this)); |
| 77 | } |