1*80814287SRaphael Isemann //===-- OptionValueRegex.cpp ----------------------------------------------===//
267cc0636SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
667cc0636SGreg Clayton //
767cc0636SGreg Clayton //===----------------------------------------------------------------------===//
867cc0636SGreg Clayton
967cc0636SGreg Clayton #include "lldb/Interpreter/OptionValueRegex.h"
1067cc0636SGreg Clayton
11bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
1267cc0636SGreg Clayton
1367cc0636SGreg Clayton using namespace lldb;
1467cc0636SGreg Clayton using namespace lldb_private;
1567cc0636SGreg Clayton
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)16b9c1b51eSKate Stone void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
17b9c1b51eSKate Stone uint32_t dump_mask) {
1867cc0636SGreg Clayton if (dump_mask & eDumpOptionType)
1967cc0636SGreg Clayton strm.Printf("(%s)", GetTypeAsCString());
20b9c1b51eSKate Stone if (dump_mask & eDumpOptionValue) {
2167cc0636SGreg Clayton if (dump_mask & eDumpOptionType)
2267cc0636SGreg Clayton strm.PutCString(" = ");
23b9c1b51eSKate Stone if (m_regex.IsValid()) {
2495eae423SZachary Turner llvm::StringRef regex_text = m_regex.GetText();
2595eae423SZachary Turner strm.Printf("%s", regex_text.str().c_str());
2667cc0636SGreg Clayton }
2767cc0636SGreg Clayton }
2867cc0636SGreg Clayton }
2967cc0636SGreg Clayton
SetValueFromString(llvm::StringRef value,VarSetOperationType op)3097206d57SZachary Turner Status OptionValueRegex::SetValueFromString(llvm::StringRef value,
31b9c1b51eSKate Stone VarSetOperationType op) {
3297206d57SZachary Turner Status error;
33b9c1b51eSKate Stone switch (op) {
3467cc0636SGreg Clayton case eVarSetOperationInvalid:
3567cc0636SGreg Clayton case eVarSetOperationInsertBefore:
3667cc0636SGreg Clayton case eVarSetOperationInsertAfter:
3767cc0636SGreg Clayton case eVarSetOperationRemove:
3867cc0636SGreg Clayton case eVarSetOperationAppend:
39c95f7e2aSPavel Labath error = OptionValue::SetValueFromString(value, op);
4067cc0636SGreg Clayton break;
4167cc0636SGreg Clayton
4267cc0636SGreg Clayton case eVarSetOperationClear:
4367cc0636SGreg Clayton Clear();
44332e8b1cSGreg Clayton NotifyValueChanged();
4567cc0636SGreg Clayton break;
4667cc0636SGreg Clayton
4767cc0636SGreg Clayton case eVarSetOperationReplace:
4867cc0636SGreg Clayton case eVarSetOperationAssign:
49f9d90bc5SJan Kratochvil m_regex = RegularExpression(value);
50f9d90bc5SJan Kratochvil if (m_regex.IsValid()) {
5167cc0636SGreg Clayton m_value_was_set = true;
52332e8b1cSGreg Clayton NotifyValueChanged();
533af3f1e8SJonas Devlieghere } else if (llvm::Error err = m_regex.GetError()) {
543af3f1e8SJonas Devlieghere error.SetErrorString(llvm::toString(std::move(err)));
55b9c1b51eSKate Stone } else {
563af3f1e8SJonas Devlieghere error.SetErrorString("regex error");
5767cc0636SGreg Clayton }
5867cc0636SGreg Clayton break;
5967cc0636SGreg Clayton }
6067cc0636SGreg Clayton return error;
6167cc0636SGreg Clayton }
62