reading file content (with unicode support) v_0 v0.13
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 26 Jul 2019 22:50:35 +0200
branchv_0
changeset 22 31e7f1994b12
parent 21 1252acdc5a5a
child 23 622940f68180
reading file content (with unicode support)
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: