Skip to content

Commit 9ac55f8

Browse files
committed
next: hwmon: replace std::regex_match to std::regex_search
Quote from cppreference: regex_match - attempts to match a regular expression to an ENTIRE character sequence regex_search - attempts to match a regular expression to ANY PART of a character sequence in this case we want partial matches instead of full matches if we want full match, we should specify it in regex expression
1 parent 482b29b commit 9ac55f8

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

mangohud-next/server/metrics/hwmon.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,30 @@ std::string HwmonBase::find_hwmon_dir_by_name(const std::string& name) {
106106
auto hwmon_dir = entry.path().string();
107107
auto hwmon_name = hwmon_dir + "/name";
108108

109+
SPDLOG_TRACE("Opening {}", hwmon_name);
110+
109111
std::ifstream name_stream(hwmon_name);
110112
std::string name_content;
111113

112-
if (!name_stream.is_open())
114+
if (!name_stream.is_open()) {
115+
SPDLOG_TRACE("Failed to open {}", hwmon_name);
113116
continue;
117+
}
114118

115119
std::getline(name_stream, name_content);
116120

117121
std::smatch matches;
118122
std::regex rx(name);
119123

120-
if (!std::regex_match(name_content, matches, rx))
124+
if (!std::regex_search(name_content, matches, rx)) {
125+
SPDLOG_TRACE(
126+
"'{}' sensor name '{}' doesn't match regex '{}'",
127+
hwmon_dir, name_content, name
128+
);
121129
continue;
130+
}
131+
132+
SPDLOG_TRACE("'{}' sensor name '{}' matches regex '{}'", hwmon_dir, name_content, name);
122133

123134
// return the first sensor with specified name
124135
return hwmon_dir;

0 commit comments

Comments
 (0)