brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 30e307a Raw
69 lines · cpp
1//===-- OptionValueRegex.cpp ----------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Interpreter/OptionValueRegex.h"10 11#include "lldb/Interpreter/OptionValue.h"12#include "lldb/Utility/Stream.h"13 14using namespace lldb;15using namespace lldb_private;16 17void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,18                                 uint32_t dump_mask) {19  if (dump_mask & eDumpOptionType)20    strm.Printf("(%s)", GetTypeAsCString());21  if (dump_mask & eDumpOptionValue) {22    if (dump_mask & eDumpOptionType)23      strm.PutCString(" = ");24    if (m_regex.IsValid()) {25      llvm::StringRef regex_text = m_regex.GetText();26      strm.Printf("%s", regex_text.str().c_str());27    }28    if (dump_mask & eDumpOptionDefaultValue &&29        m_regex.GetText() != m_default_regex_str &&30        !m_default_regex_str.empty()) {31      DefaultValueFormat label(strm);32      strm.PutCString(m_default_regex_str);33    }34  }35}36 37Status OptionValueRegex::SetValueFromString(llvm::StringRef value,38                                            VarSetOperationType op) {39  Status 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;48 49  case eVarSetOperationClear:50    Clear();51    NotifyValueChanged();52    break;53 54  case eVarSetOperationReplace:55  case eVarSetOperationAssign:56    m_regex = RegularExpression(value);57    if (m_regex.IsValid()) {58      m_value_was_set = true;59      NotifyValueChanged();60    } else if (llvm::Error err = m_regex.GetError()) {61      return Status::FromError(std::move(err));62    } else {63      return Status::FromErrorString("regex error");64    }65    break;66  }67  return error;68}69