Skip to content

Commit

Permalink
Fix GCC error
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Aug 18, 2024
1 parent 7b54d19 commit 09c4b93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace i18n_check
bool valid_utf8_file(const std::wstring& file_name, bool& startsWithBom)
{
startsWithBom = false;
std::ifstream ifs(file_name);
std::ifstream ifs(i18n_string_util::lazy_wstring_to_string(file_name));
if (!ifs)
{
return false;
Expand All @@ -37,7 +37,7 @@ namespace i18n_check
//------------------------------------------------------
std::pair<bool, std::wstring> read_utf16_file(const std::wstring& file_name)
{
std::ifstream fs8(file_name);
std::ifstream fs8(i18n_string_util::lazy_wstring_to_string(file_name));
if (!fs8.is_open())
{
std::wcout << L"Could not open " << file_name << L"\n";
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace i18n_check
return std::make_pair(false, std::wstring{});
}

std::ifstream fs8(file_name);
std::ifstream fs8(i18n_string_util::lazy_wstring_to_string(file_name));
if (!fs8.is_open())
{
std::wcout << L"Could not open " << file_name << L"\n";
Expand Down
18 changes: 18 additions & 0 deletions src/i18n_string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ namespace i18n_string_util
return retVal;
}

/** @brief Converts a wstring to string (assuming that the string is simple 8-bit ASCII).
@param str The string to convert.
@returns The string, converted to a wstring.
@warning This assumes 8-bit ASCII strings and does not perform any sort
of charset conversion. This should only be used for very simple strings,
such as `what()` from an untranslated `std::exception`.*/
[[nodiscard]]
inline std::string lazy_wstring_to_string(const std::wstring& str)
{
std::string retVal;
retVal.reserve(str.length());
for (const auto& ch : str)
{
retVal += static_cast<char>(ch);
}
return retVal;
}

/// @brief Converts escaped control characters (e.g., "\n")
/// inside of a string into spaces.
/// @param[out] str The string being escaped.
Expand Down

0 comments on commit 09c4b93

Please sign in to comment.