Better handling of utf to wchar
This commit is contained in:
		@@ -18,6 +18,7 @@
 | 
				
			|||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <thread>
 | 
					#include <thread>
 | 
				
			||||||
#include <array>
 | 
					#include <array>
 | 
				
			||||||
 | 
					#include <cassert>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -501,20 +502,16 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target)
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int result_size = static_cast<int>(target.capacity());
 | 
					    // find the size to allocate for the result buffer
 | 
				
			||||||
    if (str_size + 1 > result_size)
 | 
					    int result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (result_size > 0)
 | 
					    if (result_size > 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        target.resize(result_size);
 | 
					        target.resize(result_size);
 | 
				
			||||||
        result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, target.data(), result_size);
 | 
					        result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, target.data(), result_size);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (result_size  > 0)
 | 
					        if (result_size  > 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            target.resize(result_size);
 | 
					            assert result_size == target.size();
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user