1 //===-- OptionValueRegex.h --------------------------------------*- C++ -*-===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_INTERPRETER_OPTIONVALUEREGEX_H 10 #define LLDB_INTERPRETER_OPTIONVALUEREGEX_H 11 12 #include "lldb/Interpreter/OptionValue.h" 13 #include "lldb/Utility/RegularExpression.h" 14 15 namespace lldb_private { 16 17 class OptionValueRegex : public OptionValue { 18 public: 19 OptionValueRegex(const char *value = nullptr) OptionValue()20 : OptionValue(), m_regex(llvm::StringRef::withNullAsEmpty(value)), 21 m_default_regex_str(llvm::StringRef::withNullAsEmpty(value).str()) {} 22 23 ~OptionValueRegex() override = default; 24 25 // Virtual subclass pure virtual overrides 26 GetType()27 OptionValue::Type GetType() const override { return eTypeRegex; } 28 29 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 30 uint32_t dump_mask) override; 31 32 Status 33 SetValueFromString(llvm::StringRef value, 34 VarSetOperationType op = eVarSetOperationAssign) override; 35 Status 36 SetValueFromString(const char *, 37 VarSetOperationType = eVarSetOperationAssign) = delete; 38 Clear()39 void Clear() override { 40 m_regex = RegularExpression(m_default_regex_str); 41 m_value_was_set = false; 42 } 43 44 lldb::OptionValueSP DeepCopy() const override; 45 46 // Subclass specific functions GetCurrentValue()47 const RegularExpression *GetCurrentValue() const { 48 return (m_regex.IsValid() ? &m_regex : nullptr); 49 } 50 SetCurrentValue(const char * value)51 void SetCurrentValue(const char *value) { 52 if (value && value[0]) 53 m_regex = RegularExpression(llvm::StringRef(value)); 54 else 55 m_regex = RegularExpression(); 56 } 57 IsValid()58 bool IsValid() const { return m_regex.IsValid(); } 59 60 protected: 61 RegularExpression m_regex; 62 std::string m_default_regex_str; 63 }; 64 65 } // namespace lldb_private 66 67 #endif // LLDB_INTERPRETER_OPTIONVALUEREGEX_H 68