diff --git a/subprojects/nowide.wrap b/subprojects/nowide.wrap index 04677b1..1619a56 100644 --- a/subprojects/nowide.wrap +++ b/subprojects/nowide.wrap @@ -2,6 +2,6 @@ url = https://github.com/boostorg/nowide # closest commit to v11.1.4 on the standalone branch revision = 960c2016a259275fa9dda68f34624bde87d887bd -# Overlays subproject/packagefiles/nowide-standalone over the fresh git +# Overlays subproject/packagefiles/nowide over the fresh git # clone of nowide patch_directory = nowide \ No newline at end of file diff --git a/tests/nowide.cpp b/tests/nowide.cpp index bda097d..ff2ac9a 100644 --- a/tests/nowide.cpp +++ b/tests/nowide.cpp @@ -9,42 +9,39 @@ #include #include +template +void check_file(T& file) { + if (not file) { + nowide::cerr << "Can't open file" << std::endl; + return; + } + std::size_t total_lines = 0; + while (file) { + if(file.get() == '\n') { + total_lines++; + } + } + nowide::cout << "File has " << total_lines << " lines" << std::endl; +} + int main() { const char* _filepath = tinyfd_openFileDialog( "Open File", nullptr, 0, nullptr, nullptr, false ); if (_filepath == nullptr) { nowide::cerr << "No file chosen" << std::endl; + return 0; } - nowide::cout << "_filepath received, seen through nowide::cout : " << _filepath << std::endl; - std::cout << "_filepath received, seen through std::cout : " << _filepath << std::endl; - + nowide::cout << "const char* _filepath = " << _filepath << std::endl; + auto u8string = std::u8string(_filepath, _filepath + std::strlen(_filepath)); + nowide::cout << "std::u8string{_filepath)} = " << reinterpret_cast(u8string.c_str()) << std::endl; - nowide::cout << "converted to std::u8string, seen through nowide::cout : " << reinterpret_cast(u8string.c_str()) << std::endl; - std::cout << "converted to std::u8string, seen through std::cout : " << reinterpret_cast(u8string.c_str()) << std::endl; + std::filesystem::path u8path{u8string}; + nowide::cout << "std::filesystem::path{u8string} = " << u8path << std::endl; - auto filepath = std::filesystem::path{_filepath}; - - nowide::cout << "_filepath passed to std::filesystem::path, seen through nowide::cout : " << filepath << std::endl; - std::cout << "_filepath passed to std::filesystem::path, seen through std::cout : " << filepath << std::endl; - - auto u8path = std::filesystem::path{u8string}; - - nowide::cout << "u8string passed to std::filesystem::path, seen through nowide::cout : " << u8path << std::endl; - std::cout << "u8string passed to std::filesystem::path, seen through std::cout : " << u8path << std::endl; - - nowide::ifstream f(filepath.string().c_str()); // argv[1] - is UTF-8 - if(not f) { - nowide::cerr << "Can't open " << filepath << std::endl; - return 1; - } - std::size_t total_lines = 0; - while (f) { - if(f.get() == '\n') { - total_lines++; - } - } - nowide::cout << "File " << filepath << " has " << total_lines << " lines" << std::endl; + nowide::cout << "nowide::ifstream{u8path} : " << std::endl; + nowide::ifstream file_from_path(u8path.string()); + check_file(file_from_path); return 0; } \ No newline at end of file