fix code style
This commit is contained in:
@@ -1,28 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
class SystemHelper
|
||||
{
|
||||
class SystemHelper {
|
||||
public:
|
||||
static std::string get_command_output(const char *cmd)
|
||||
{
|
||||
static std::string get_command_output(const char *cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::unique_ptr<FILE, int (*)(FILE *)> pipe(popen(cmd, "r"), pclose);
|
||||
|
||||
if (!pipe)
|
||||
{
|
||||
if (!pipe) {
|
||||
throw std::runtime_error("popen() failed!");
|
||||
}
|
||||
|
||||
// Read the output a chunk at a time until the stream ends
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
|
||||
{
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
@@ -30,11 +26,9 @@ class SystemHelper
|
||||
}
|
||||
|
||||
// Read an entire file into a string. Throws std::runtime_error on failure.
|
||||
static std::string read_file_to_string(const std::string &path)
|
||||
{
|
||||
static std::string read_file_to_string(const std::string &path) {
|
||||
std::ifstream in(path, std::ios::in | std::ios::binary);
|
||||
if (!in)
|
||||
{
|
||||
if (!in) {
|
||||
throw std::runtime_error("Failed to open file: " + path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user