Parse cpuinfo without std::regex
This commit is contained in:
parent
87f3a2b224
commit
6984ef9e75
1 changed files with 14 additions and 5 deletions
|
|
@ -163,8 +163,9 @@ std::string getCurrentProcessName()
|
|||
#include <sys/wait.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#include <absl/strings/strip.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <vector>
|
||||
#include <regex>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
|
|
@ -305,14 +306,22 @@ std::string getProcessorName()
|
|||
std::string name;
|
||||
std::string line;
|
||||
std::ifstream in("/proc/cpuinfo", std::ios::binary);
|
||||
std::regex re("^model name\\s*:\\s*(.*)");
|
||||
|
||||
line.reserve(256);
|
||||
|
||||
while (name.empty() && std::getline(in, line) && !line.empty()) {
|
||||
std::smatch match;
|
||||
if (std::regex_match(line, match, re))
|
||||
name = match[1];
|
||||
size_t pos = line.find(':');
|
||||
if (pos == line.npos)
|
||||
continue;
|
||||
|
||||
absl::string_view left = absl::string_view(line).substr(0, pos);
|
||||
absl::string_view right = absl::string_view(line).substr(pos + 1);
|
||||
|
||||
left = absl::StripAsciiWhitespace(left);
|
||||
right = absl::StripAsciiWhitespace(right);
|
||||
|
||||
if (left == "model name")
|
||||
name = std::string(right);
|
||||
}
|
||||
|
||||
if (name.empty())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue