Skip to content

Commit

Permalink
Fix macOS compilation errors (#81)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rapito authored Aug 17, 2023
1 parent 59f2f69 commit 19e14a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Externals/semver/src/Semver200_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ namespace version {
for (const auto& r : allowed_prerel_id_chars) {
res |= (c >= r.first && c <= r.second);
}
//if (!res)
// throw Parse_error("invalid character encountered: " + string(1, c));
// 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));
}

inline bool is_identifier_numeric(const string& id) {
Expand Down
15 changes: 12 additions & 3 deletions Source/Core/Common/StringUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <type_traits>
#include <vector>
#include <unordered_map>

#include <fmt/format.h>

Expand Down Expand Up @@ -593,7 +594,7 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size)
template <typename T>
#ifdef __APPLE__
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
std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_view<T> input)
#endif
Expand Down Expand Up @@ -665,6 +666,14 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v
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>
std::string CodeToUTF8(const char* fromcode, std::basic_string_view<T> input)
{
Expand Down Expand Up @@ -746,10 +755,10 @@ std::string UTF8ToSHIFTJIS(std::string_view input)
fallbacks->mb_to_wc_fallback = nullptr;
fallbacks->wc_to_mb_fallback = 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);
#else
auto str = CodeTo("SJIS", "UTF-8", input);
auto str = CodeTo("SJIS", "UTF-8", std::string_view(input));
#endif
return str;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/UICommon/UICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ void SetUserDirectory(std::string custom_path)
}
}
#endif
}
#endif
}
#endif
File::SetUserPath(D_USER_IDX, std::move(user_path));
}
Expand Down

0 comments on commit 19e14a5

Please sign in to comment.