Fix macOS compilation errors (#81)

* Move #endif to proper location on UICommon.cpp preventing compilation because of syntax error

* Add missing include for unordered map and missing CodeTo implementation from Ishiiruka
+ Adjust code to use string_view

* Trick compiler to think var is being used on Semver200_parser.cpp to prevent compilation errors on macos
This commit is contained in:
Robert Peralta 2023-08-17 01:01:01 -04:00 committed by GitHub
commit 19e14a5608
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View file

@ -92,7 +92,10 @@ namespace version {
for (const auto& r : allowed_prerel_id_chars) { for (const auto& r : allowed_prerel_id_chars) {
res |= (c >= r.first && c <= r.second); res |= (c >= r.first && c <= r.second);
} }
//if (!res) // Trick the compiler that this is being used so it stops crashing on macos
(void)res;
// if (!res)
// throw Parse_error("invalid character encountered: " + string(1, c)); // throw Parse_error("invalid character encountered: " + string(1, c));
} }

View file

@ -20,6 +20,7 @@
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include <unordered_map>
#include <fmt/format.h> #include <fmt/format.h>
@ -593,7 +594,7 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size)
template <typename T> template <typename T>
#ifdef __APPLE__ #ifdef __APPLE__
std::string CodeToWithFallbacks(const char* tocode, const char* fromcode, std::string CodeToWithFallbacks(const char* tocode, const char* fromcode,
const std::basic_string<T>& input, iconv_fallbacks* fallbacks) const std::basic_string_view<T> input, iconv_fallbacks* fallbacks)
#else #else
std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_view<T> input) std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_view<T> input)
#endif #endif
@ -665,6 +666,14 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v
return result; return result;
} }
#ifdef __APPLE__
template <typename T>
std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_view<T> input)
{
return CodeToWithFallbacks(tocode, fromcode, input, nullptr);
}
#endif
template <typename T> template <typename T>
std::string CodeToUTF8(const char* fromcode, std::basic_string_view<T> input) std::string CodeToUTF8(const char* fromcode, std::basic_string_view<T> input)
{ {
@ -746,10 +755,10 @@ std::string UTF8ToSHIFTJIS(std::string_view input)
fallbacks->mb_to_wc_fallback = nullptr; fallbacks->mb_to_wc_fallback = nullptr;
fallbacks->wc_to_mb_fallback = nullptr; fallbacks->wc_to_mb_fallback = nullptr;
fallbacks->data = nullptr; fallbacks->data = nullptr;
auto str = CodeToWithFallbacks("SJIS", "UTF-8", input, fallbacks); auto str = CodeToWithFallbacks("SJIS", "UTF-8", std::string_view(input), fallbacks);
free(fallbacks); free(fallbacks);
#else #else
auto str = CodeTo("SJIS", "UTF-8", input); auto str = CodeTo("SJIS", "UTF-8", std::string_view(input));
#endif #endif
return str; return str;
} }

View file

@ -487,8 +487,8 @@ void SetUserDirectory(std::string custom_path)
} }
} }
#endif #endif
}
#endif #endif
}
#endif #endif
File::SetUserPath(D_USER_IDX, std::move(user_path)); File::SetUserPath(D_USER_IDX, std::move(user_path));
} }