nowide now kind of works ?

This commit is contained in:
Stepland 2022-04-04 00:20:45 +02:00
parent 914b8b53b6
commit d167cf2ef2
2 changed files with 25 additions and 28 deletions

View File

@ -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

View File

@ -9,42 +9,39 @@
#include <nowide/fstream.hpp>
#include <nowide/iostream.hpp>
template <class T>
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<const char*>(u8string.c_str()) << std::endl;
nowide::cout << "converted to std::u8string, seen through nowide::cout : " << reinterpret_cast<const char*>(u8string.c_str()) << std::endl;
std::cout << "converted to std::u8string, seen through std::cout : " << reinterpret_cast<const char*>(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;
}