Fix clang-format violations in file_utils files

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-29 18:34:41 +00:00
parent ceb9700239
commit 206451a997
2 changed files with 61 additions and 57 deletions

View File

@@ -9,35 +9,37 @@
*/
class FileUtils {
public:
/**
* @brief Read a file and split into lines
* @param filePath Path to the file
* @param lines Output vector of lines
* @return true if successful, false on error
*/
static bool readLines(const std::string& filePath, std::vector<std::string>& lines);
/**
* @brief Read a file and split into lines
* @param filePath Path to the file
* @param lines Output vector of lines
* @return true if successful, false on error
*/
static bool readLines(const std::string &filePath,
std::vector<std::string> &lines);
/**
* @brief Write lines to a file
* @param filePath Path to the file
* @param lines Vector of lines to write
* @return true if successful, false on error
*/
static bool writeLines(const std::string& filePath, const std::vector<std::string>& lines);
/**
* @brief Write lines to a file
* @param filePath Path to the file
* @param lines Vector of lines to write
* @return true if successful, false on error
*/
static bool writeLines(const std::string &filePath,
const std::vector<std::string> &lines);
/**
* @brief Check if a file exists
* @param filePath Path to the file
* @return true if file exists, false otherwise
*/
static bool fileExists(const std::string& filePath);
/**
* @brief Check if a file exists
* @param filePath Path to the file
* @return true if file exists, false otherwise
*/
static bool fileExists(const std::string &filePath);
/**
* @brief Get file size in bytes
* @param filePath Path to the file
* @return File size, or -1 on error
*/
static long getFileSize(const std::string& filePath);
/**
* @brief Get file size in bytes
* @param filePath Path to the file
* @return File size, or -1 on error
*/
static long getFileSize(const std::string &filePath);
};
#endif // FILE_UTILS_H

View File

@@ -3,45 +3,47 @@
#include <sstream>
#include <sys/stat.h>
bool FileUtils::readLines(const std::string& filePath, std::vector<std::string>& lines) {
std::ifstream file(filePath);
if (!file.is_open()) {
return false;
}
bool FileUtils::readLines(const std::string &filePath,
std::vector<std::string> &lines) {
std::ifstream file(filePath);
if (!file.is_open()) {
return false;
}
lines.clear();
std::string line;
while (std::getline(file, line)) {
lines.push_back(line);
}
lines.clear();
std::string line;
while (std::getline(file, line)) {
lines.push_back(line);
}
file.close();
return true;
file.close();
return true;
}
bool FileUtils::writeLines(const std::string& filePath, const std::vector<std::string>& lines) {
std::ofstream file(filePath);
if (!file.is_open()) {
return false;
}
bool FileUtils::writeLines(const std::string &filePath,
const std::vector<std::string> &lines) {
std::ofstream file(filePath);
if (!file.is_open()) {
return false;
}
for (const auto& line : lines) {
file << line << "\n";
}
for (const auto &line : lines) {
file << line << "\n";
}
file.close();
return true;
file.close();
return true;
}
bool FileUtils::fileExists(const std::string& filePath) {
struct stat buffer;
return (stat(filePath.c_str(), &buffer) == 0);
bool FileUtils::fileExists(const std::string &filePath) {
struct stat buffer;
return (stat(filePath.c_str(), &buffer) == 0);
}
long FileUtils::getFileSize(const std::string& filePath) {
struct stat buffer;
if (stat(filePath.c_str(), &buffer) != 0) {
return -1;
}
return buffer.st_size;
long FileUtils::getFileSize(const std::string &filePath) {
struct stat buffer;
if (stat(filePath.c_str(), &buffer) != 0) {
return -1;
}
return buffer.st_size;
}