Skip to content

Commit

Permalink
Replace <format> with fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulgen301 committed Jan 17, 2023
1 parent b0a177c commit 5b1d4c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ endif ()

# Link libraries

# Link fmt
find_package(fmt REQUIRED)
target_link_libraries(standard fmt::fmt)
list(APPEND PCH_EXTRA <fmt/format.h> <fmt/printf.h>)

# Link Freetype
if (NOT USE_CONSOLE)
find_package(Freetype REQUIRED)
Expand Down
7 changes: 4 additions & 3 deletions src/StdStringEncodingConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

#include "StdStringEncodingConverter.h"

#include <format>
#include <memory>
#include <stdexcept>
#include <string>

#include <fmt/format.h>

namespace
{
template<typename T>
Expand Down Expand Up @@ -48,15 +49,15 @@ namespace
const int convertedSize{ConversionFunc(CP_ACP, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, std::forward<Args>(args)...)};
if (!convertedSize)
{
throw std::runtime_error{std::format("Querying output size failed: {:x}", GetLastError())};
throw std::runtime_error{fmt::format("Querying output size failed: {:x}", GetLastError())};
}

const auto converted = std::make_unique_for_overwrite<typename ReturnType::value_type[]>(static_cast<std::size_t>(convertedSize));
const int result{ConversionFunc(CP_ACP, 0, input.data(), static_cast<int>(input.size()), converted.get(), convertedSize, std::forward<Args>(args)...)};

if (result != convertedSize)
{
throw std::runtime_error{std::format("Conversion returned {} when it was expected to return {}", result, convertedSize)};
throw std::runtime_error{fmt::format("Conversion returned {} when it was expected to return {}", result, convertedSize)};
}

return ReturnType{converted.get(), static_cast<std::size_t>(convertedSize)};
Expand Down

0 comments on commit 5b1d4c0

Please sign in to comment.