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) 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 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 39 bool Clear() override { 40 m_regex = RegularExpression(m_default_regex_str); 41 m_value_was_set = false; 42 return true; 43 } 44 45 lldb::OptionValueSP DeepCopy() const override; 46 47 // Subclass specific functions 48 const RegularExpression *GetCurrentValue() const { 49 return (m_regex.IsValid() ? &m_regex : nullptr); 50 } 51 52 void SetCurrentValue(const char *value) { 53 if (value && value[0]) 54 m_regex = RegularExpression(llvm::StringRef(value)); 55 else 56 m_regex = RegularExpression(); 57 } 58 59 bool IsValid() const { return m_regex.IsValid(); } 60 61 protected: 62 RegularExpression m_regex; 63 std::string m_default_regex_str; 64 }; 65 66 } // namespace lldb_private 67 68 #endif // LLDB_INTERPRETER_OPTIONVALUEREGEX_H 69