Merge pull request #278 from rbsheth/string_fix

Use std::string for GetKey function
This commit is contained in:
Syoyo Fujita 2020-07-11 03:41:11 +09:00 committed by GitHub
commit c9d6c5b9b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1253,7 +1253,8 @@ struct FsCallbacks {
bool FileExists(const std::string &abs_filename, void *); bool FileExists(const std::string &abs_filename, void *);
/// ///
/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to `C:\Users\tinygltf\AppData`) /// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to
/// `C:\Users\tinygltf\AppData`)
/// ///
/// @param[in] filepath File path string. Assume UTF-8 /// @param[in] filepath File path string. Assume UTF-8
/// @param[in] userdata User data. Set to `nullptr` if you don't need it. /// @param[in] userdata User data. Set to `nullptr` if you don't need it.
@ -2638,7 +2639,8 @@ bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in); __gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
std::istream f(&wfile_buf); std::istream f(&wfile_buf);
#elif defined(_MSC_VER) || defined(_LIBCPP_VERSION) #elif defined(_MSC_VER) || defined(_LIBCPP_VERSION)
// For libcxx, assume _LIBCPP_HAS_OPEN_WITH_WCHAR is defined to accept `wchar_t *` // For libcxx, assume _LIBCPP_HAS_OPEN_WITH_WCHAR is defined to accept
// `wchar_t *`
std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary); std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary);
#else #else
// Unknown compiler/runtime // Unknown compiler/runtime
@ -3000,7 +3002,9 @@ json_const_iterator ObjectEnd(const json &o) {
#endif #endif
} }
const char *GetKey(json_const_iterator &it) { // Making this a const char* results in a pointer to a temporary when
// TINYGLTF_USE_RAPIDJSON is off.
std::string GetKey(json_const_iterator &it) {
#ifdef TINYGLTF_USE_RAPIDJSON #ifdef TINYGLTF_USE_RAPIDJSON
return it->name.GetString(); return it->name.GetString();
#else #else
@ -7343,8 +7347,9 @@ static void SerializeGltfModel(Model *model, json &o) {
// Also add "KHR_lights_punctual" to `extensionsUsed` // Also add "KHR_lights_punctual" to `extensionsUsed`
{ {
auto has_khr_lights_punctual = std::find_if( auto has_khr_lights_punctual =
extensionsUsed.begin(), extensionsUsed.end(), [](const std::string &s) { std::find_if(extensionsUsed.begin(), extensionsUsed.end(),
[](const std::string &s) {
return (s.compare("KHR_lights_punctual") == 0); return (s.compare("KHR_lights_punctual") == 0);
}); });