Skip to content

Commit 7e5afae

Browse files
committed
feat: regex_valid return std::optional<wregex>
1 parent 7617abf commit 7e5afae

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

include/MaaUtils/Encoding.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <optional>
4+
#include <regex>
35
#include <string>
46
#include <string_view>
57

@@ -11,6 +13,6 @@ MAA_NS_BEGIN
1113
MAA_UTILS_API std::wstring to_u16(std::string_view u8str);
1214
MAA_UTILS_API std::string from_u16(std::wstring_view u16str);
1315

14-
MAA_UTILS_API bool regex_valid(const std::wstring& regex);
16+
MAA_UTILS_API std::optional<std::wregex> regex_valid(const std::wstring& regex);
1517

1618
MAA_NS_END

source/Encoding/Encoding.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,15 @@ std::string from_u16(std::wstring_view u16str)
141141
return output;
142142
}
143143

144-
bool regex_valid(const std::wstring& regex)
144+
std::optional<std::wregex> regex_valid(const std::wstring& regex)
145145
{
146146
try {
147-
std::wregex _(regex);
147+
return std::wregex(regex);
148148
}
149149
catch (const std::regex_error& e) {
150150
LogError << e.what() << VAR(regex);
151-
return false;
151+
return std::nullopt;
152152
}
153-
return true;
154153
}
155154

156155
MAA_NS_END

0 commit comments

Comments
 (0)