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
15namespace lldb_private {
16
17class OptionValueRegex : public Cloneable<OptionValueRegex, OptionValue> {
18public:
19 OptionValueRegex(const char *value = nullptr)
20 : 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
36 void Clear() override {
37 m_regex = RegularExpression(m_default_regex_str);
38 m_value_was_set = false;
39 }
40
41 // Subclass specific functions
42 const RegularExpression *GetCurrentValue() const {
43 return (m_regex.IsValid() ? &m_regex : nullptr);
44 }
45
46 void SetCurrentValue(const char *value) {
47 if (value && value[0])
48 m_regex = RegularExpression(llvm::StringRef(value));
49 else
50 m_regex = RegularExpression();
51 }
52
53 bool IsValid() const { return m_regex.IsValid(); }
54
55protected:
56 RegularExpression m_regex;
57 std::string m_default_regex_str;
58};
59
60} // namespace lldb_private
61
62#endif // LLDB_INTERPRETER_OPTIONVALUEREGEX_H
63