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