# HG changeset patch # User František Kučera # Date 1564174235 -7200 # Node ID 31e7f1994b123dcc31cb27322f7cd74bfc289f65 # Parent 1252acdc5a5a068fd99a63c717ba6f83a8942272 reading file content (with unicode support) diff -r 1252acdc5a5a -r 31e7f1994b12 src/FileAttributeFinder.h --- a/src/FileAttributeFinder.h Fri Jul 26 22:34:30 2019 +0200 +++ b/src/FileAttributeFinder.h Fri Jul 26 22:50:35 2019 +0200 @@ -73,17 +73,18 @@ } string_t getContent(const fs::path& file) { - // TODO: better copy - // not working: - wifstream source(file); - std::wstringstream result; - for (wchar_t ch; source.get(ch); source.good()) result << ch; - return result.str(); + try { + ifstream input(file); + std::stringstream bytes; + bytes << input.rdbuf(); - //wifstream stream(file); - //std::wstringstream content; - //content << stream.rdbuf(); - //return content.str(); + // TODO: optional whitespace trimming or substring + // TODO: custom encoding + read encoding from xattr + return convertor.from_bytes(bytes.str()); + } catch (const std::range_error& e) { + // TODO: allow custom error value or fallback to HEX/Base64 + return L""; + } } protected: