F.E.I.S/tests/nowide.cpp

50 lines
1.9 KiB
C++
Raw Normal View History

#include <cstddef>
2022-04-03 17:11:31 +02:00
#include <cstring>
2022-04-03 15:59:05 +02:00
#include <filesystem>
2022-04-03 17:03:45 +02:00
#include <iostream>
2022-04-03 17:11:31 +02:00
#include <string>
2022-04-03 15:59:05 +02:00
#include <tinyfiledialogs.h>
#include <nowide/args.hpp>
#include <nowide/fstream.hpp>
#include <nowide/iostream.hpp>
2022-04-03 16:55:04 +02:00
int main() {
2022-04-03 15:59:05 +02:00
const char* _filepath = tinyfd_openFileDialog(
"Open File", nullptr, 0, nullptr, nullptr, false
);
if (_filepath == nullptr) {
nowide::cerr << "No file chosen" << std::endl;
}
2022-04-03 17:03:08 +02:00
nowide::cout << "_filepath received, seen through nowide::cout : " << _filepath << std::endl;
std::cout << "_filepath received, seen through std::cout : " << _filepath << std::endl;
2022-04-03 17:11:31 +02:00
auto u8string = std::u8string(_filepath, _filepath + std::strlen(_filepath));
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;
2022-04-03 15:59:05 +02:00
auto filepath = std::filesystem::path{_filepath};
2022-04-03 17:11:31 +02:00
2022-04-03 17:03:08 +02:00
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;
2022-04-03 17:11:31 +02:00
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;
2022-04-03 15:59:05 +02:00
nowide::ifstream f(filepath.string().c_str()); // argv[1] - is UTF-8
if(not f) {
2022-04-03 16:55:04 +02:00
nowide::cerr << "Can't open " << filepath << std::endl;
return 1;
}
std::size_t total_lines = 0;
while (f) {
if(f.get() == '\n') {
total_lines++;
}
}
2022-04-03 16:51:26 +02:00
nowide::cout << "File " << filepath << " has " << total_lines << " lines" << std::endl;
return 0;
}