From d0fbd68055e3f4a796330cc8acc6c0954b5327ff Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Sep 2025 15:48:53 +0500 Subject: Run clang-format across the project --- core/utils/epoch.cc | 78 +++++++++++++------------- core/utils/epoch.hh | 30 +++++----- core/utils/physfs.cc | 152 +++++++++++++++++++++++++-------------------------- core/utils/physfs.hh | 28 +++++----- core/utils/string.cc | 114 +++++++++++++++++++------------------- core/utils/string.hh | 34 ++++++------ 6 files changed, 218 insertions(+), 218 deletions(-) (limited to 'core/utils') diff --git a/core/utils/epoch.cc b/core/utils/epoch.cc index 36bdb79..be5d4bd 100644 --- a/core/utils/epoch.cc +++ b/core/utils/epoch.cc @@ -1,39 +1,39 @@ -#include "core/pch.hh" - -#include "core/utils/epoch.hh" - -std::uint64_t utils::unix_seconds(void) -{ - const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); - return static_cast(std::chrono::duration_cast(elapsed).count()); -} - -std::uint64_t utils::unix_milliseconds(void) -{ - const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); - return static_cast(std::chrono::duration_cast(elapsed).count()); -} - -std::uint64_t utils::unix_microseconds(void) -{ - const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); - return static_cast(std::chrono::duration_cast(elapsed).count()); -} - -std::int64_t utils::signed_unix_seconds(void) -{ - const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); - return static_cast(std::chrono::duration_cast(elapsed).count()); -} - -std::int64_t utils::signed_unix_milliseconds(void) -{ - const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); - return static_cast(std::chrono::duration_cast(elapsed).count()); -} - -std::int64_t utils::signed_unix_microseconds(void) -{ - const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); - return static_cast(std::chrono::duration_cast(elapsed).count()); -} +#include "core/pch.hh" + +#include "core/utils/epoch.hh" + +std::uint64_t utils::unix_seconds(void) +{ + const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(elapsed).count()); +} + +std::uint64_t utils::unix_milliseconds(void) +{ + const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(elapsed).count()); +} + +std::uint64_t utils::unix_microseconds(void) +{ + const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(elapsed).count()); +} + +std::int64_t utils::signed_unix_seconds(void) +{ + const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(elapsed).count()); +} + +std::int64_t utils::signed_unix_milliseconds(void) +{ + const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(elapsed).count()); +} + +std::int64_t utils::signed_unix_microseconds(void) +{ + const auto elapsed = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(elapsed).count()); +} diff --git a/core/utils/epoch.hh b/core/utils/epoch.hh index 4bf5460..1df564c 100644 --- a/core/utils/epoch.hh +++ b/core/utils/epoch.hh @@ -1,15 +1,15 @@ -#pragma once - -namespace utils -{ -std::uint64_t unix_seconds(void); -std::uint64_t unix_milliseconds(void); -std::uint64_t unix_microseconds(void); -} // namespace utils - -namespace utils -{ -std::int64_t signed_unix_seconds(void); -std::int64_t signed_unix_milliseconds(void); -std::int64_t signed_unix_microseconds(void); -} // namespace utils +#pragma once + +namespace utils +{ +std::uint64_t unix_seconds(void); +std::uint64_t unix_milliseconds(void); +std::uint64_t unix_microseconds(void); +} // namespace utils + +namespace utils +{ +std::int64_t signed_unix_seconds(void); +std::int64_t signed_unix_milliseconds(void); +std::int64_t signed_unix_microseconds(void); +} // namespace utils diff --git a/core/utils/physfs.cc b/core/utils/physfs.cc index cb310df..b801963 100644 --- a/core/utils/physfs.cc +++ b/core/utils/physfs.cc @@ -1,76 +1,76 @@ -#include "core/pch.hh" - -#include "core/utils/physfs.hh" - -bool utils::read_file(std::string_view path, std::vector& buffer) -{ - auto file = PHYSFS_openRead(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_sint64 file_size = PHYSFS_fileLength(file); - buffer.resize(static_cast(file_size)); - - PHYSFS_readBytes(file, buffer.data(), file_size); - PHYSFS_close(file); - - return true; -} - -bool utils::read_file(std::string_view path, std::string& buffer) -{ - auto file = PHYSFS_openRead(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_sint64 file_size = PHYSFS_fileLength(file); - buffer.resize(static_cast(file_size)); - - PHYSFS_readBytes(file, buffer.data(), file_size); - PHYSFS_close(file); - - return true; -} - -bool utils::write_file(std::string_view path, const std::vector& buffer) -{ - auto file = PHYSFS_openWrite(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); - PHYSFS_close(file); - - return true; -} - -bool utils::write_file(std::string_view path, const std::string& buffer) -{ - auto file = PHYSFS_openWrite(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); - PHYSFS_close(file); - - return true; -} - -std::string_view utils::physfs_error(void) -{ - auto error_code = PHYSFS_getLastErrorCode(); - auto error_string = PHYSFS_getErrorByCode(error_code); - return std::string_view(error_string, std::strlen(error_string)); -} +#include "core/pch.hh" + +#include "core/utils/physfs.hh" + +bool utils::read_file(std::string_view path, std::vector& buffer) +{ + auto file = PHYSFS_openRead(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + return false; + } + + PHYSFS_sint64 file_size = PHYSFS_fileLength(file); + buffer.resize(static_cast(file_size)); + + PHYSFS_readBytes(file, buffer.data(), file_size); + PHYSFS_close(file); + + return true; +} + +bool utils::read_file(std::string_view path, std::string& buffer) +{ + auto file = PHYSFS_openRead(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + return false; + } + + PHYSFS_sint64 file_size = PHYSFS_fileLength(file); + buffer.resize(static_cast(file_size)); + + PHYSFS_readBytes(file, buffer.data(), file_size); + PHYSFS_close(file); + + return true; +} + +bool utils::write_file(std::string_view path, const std::vector& buffer) +{ + auto file = PHYSFS_openWrite(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + return false; + } + + PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); + PHYSFS_close(file); + + return true; +} + +bool utils::write_file(std::string_view path, const std::string& buffer) +{ + auto file = PHYSFS_openWrite(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + return false; + } + + PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); + PHYSFS_close(file); + + return true; +} + +std::string_view utils::physfs_error(void) +{ + auto error_code = PHYSFS_getLastErrorCode(); + auto error_string = PHYSFS_getErrorByCode(error_code); + return std::string_view(error_string, std::strlen(error_string)); +} diff --git a/core/utils/physfs.hh b/core/utils/physfs.hh index 4af94dc..220954e 100644 --- a/core/utils/physfs.hh +++ b/core/utils/physfs.hh @@ -1,14 +1,14 @@ -#pragma once - -namespace utils -{ -bool read_file(std::string_view path, std::vector& buffer); -bool read_file(std::string_view path, std::string& buffer); -bool write_file(std::string_view path, const std::vector& buffer); -bool write_file(std::string_view path, const std::string& buffer); -} // namespace utils - -namespace utils -{ -std::string_view physfs_error(void); -} // namespace utils +#pragma once + +namespace utils +{ +bool read_file(std::string_view path, std::vector& buffer); +bool read_file(std::string_view path, std::string& buffer); +bool write_file(std::string_view path, const std::vector& buffer); +bool write_file(std::string_view path, const std::string& buffer); +} // namespace utils + +namespace utils +{ +std::string_view physfs_error(void); +} // namespace utils diff --git a/core/utils/string.cc b/core/utils/string.cc index dd3d567..4bdc073 100644 --- a/core/utils/string.cc +++ b/core/utils/string.cc @@ -1,57 +1,57 @@ -#include "core/pch.hh" - -#include "core/utils/string.hh" - -constexpr static const char* WHITESPACE_CHARS = " \t\r\n"; - -bool utils::is_whitespace(const std::string& string) -{ - if(string.find_first_not_of(WHITESPACE_CHARS) == std::string::npos) { - return true; - } - else if((string.size() == 1) && string[0] == 0x00) { - return true; - } - else { - return string.empty(); - } -} - -std::string utils::join(const std::vector& strings, const std::string& separator) -{ - std::ostringstream stream; - for(const std::string& str : strings) - stream << str << separator; - return stream.str(); -} - -std::vector utils::split(const std::string& string, const std::string& separator) -{ - std::size_t pos = 0; - std::size_t prev = 0; - std::vector result; - - while((pos = string.find(separator, prev)) != std::string::npos) { - result.push_back(string.substr(prev, pos - prev)); - prev = pos + separator.length(); - } - - if(prev <= string.length()) { - result.push_back(string.substr(prev, string.length() - prev)); - } - - return result; -} - -std::string utils::trim_whitespace(const std::string& string) -{ - auto su = string.find_first_not_of(WHITESPACE_CHARS); - auto sv = string.find_last_not_of(WHITESPACE_CHARS); - - if(su == std::string::npos) { - return std::string(); - } - else { - return string.substr(su, sv - su + 1); - } -} +#include "core/pch.hh" + +#include "core/utils/string.hh" + +constexpr static const char* WHITESPACE_CHARS = " \t\r\n"; + +bool utils::is_whitespace(const std::string& string) +{ + if(string.find_first_not_of(WHITESPACE_CHARS) == std::string::npos) { + return true; + } + else if((string.size() == 1) && string[0] == 0x00) { + return true; + } + else { + return string.empty(); + } +} + +std::string utils::join(const std::vector& strings, const std::string& separator) +{ + std::ostringstream stream; + for(const std::string& str : strings) + stream << str << separator; + return stream.str(); +} + +std::vector utils::split(const std::string& string, const std::string& separator) +{ + std::size_t pos = 0; + std::size_t prev = 0; + std::vector result; + + while((pos = string.find(separator, prev)) != std::string::npos) { + result.push_back(string.substr(prev, pos - prev)); + prev = pos + separator.length(); + } + + if(prev <= string.length()) { + result.push_back(string.substr(prev, string.length() - prev)); + } + + return result; +} + +std::string utils::trim_whitespace(const std::string& string) +{ + auto su = string.find_first_not_of(WHITESPACE_CHARS); + auto sv = string.find_last_not_of(WHITESPACE_CHARS); + + if(su == std::string::npos) { + return std::string(); + } + else { + return string.substr(su, sv - su + 1); + } +} diff --git a/core/utils/string.hh b/core/utils/string.hh index 827c3ca..0e896fd 100644 --- a/core/utils/string.hh +++ b/core/utils/string.hh @@ -1,17 +1,17 @@ -#pragma once - -namespace utils -{ -bool is_whitespace(const std::string& string); -} // namespace utils - -namespace utils -{ -std::string join(const std::vector& strings, const std::string& separator); -std::vector split(const std::string& string, const std::string& separator); -} // namespace utils - -namespace utils -{ -std::string trim_whitespace(const std::string& string); -} // namespace utils +#pragma once + +namespace utils +{ +bool is_whitespace(const std::string& string); +} // namespace utils + +namespace utils +{ +std::string join(const std::vector& strings, const std::string& separator); +std::vector split(const std::string& string, const std::string& separator); +} // namespace utils + +namespace utils +{ +std::string trim_whitespace(const std::string& string); +} // namespace utils -- cgit