-
-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regex parsing for xeon cpu names
- Loading branch information
Steffen Winter
committed
Aug 11, 2024
1 parent
00c9088
commit 38f9cf0
Showing
4 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "parse_cpu_names.hpp" | ||
|
||
#include <cstddef> | ||
#include <optional> | ||
#include <regex> | ||
#include <string> | ||
|
||
auto parse_xeon_name(const std::string& name) -> std::optional<std::string> { | ||
std::regex regex{R"((?:\S+\(R\) ?)+ ([a-zA-Z0-9\- ]+[^ ])? ?CPU ([a-zA-Z0-9\- ]+[^ ])? ?(?:@ \d\.\d\dGHz))"}; | ||
std::smatch match{}; | ||
if (std::regex_match(name, match, regex)) { | ||
for (std::size_t i = 1; i < match.size(); ++i) { | ||
if (!match[i].str().empty()) { | ||
return match[i].str(); | ||
} | ||
} | ||
} | ||
return std::nullopt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
auto parse_xeon_name(const std::string& name) -> std::optional<std::string>; |