std.file: read, readText and UTF-8 decoding

Uranuz neuranuz at gmail.com
Thu Sep 21 15:48:20 UTC 2023


Addition:
Current solution to this problemme that I was found is:
So I just check for BOM manually. Get length of bom.sequence and 
remove that count of items from beginning. But I dont' think that 
it's convenient solution, because `who knows` how much else 
issues with UTF could happend. And I don't think that it's 
correct to handle them on the side of users of standart D 
library... I think that should be solution "out of the box". It 
could be not much effective, but it should at least "just work" 
without extra movements...
string[] getGroupsFromFile(string groupFilePath)
{
	writeln(`Parse file` ~ groupFilePath);
	string[] groupNames = [];
	char[] rawContent = cast(char[]) read(groupFilePath);
	auto bom = getBOM(cast(ubyte[]) rawContent);
	string content = cast(string) rawContent[bom.sequence.length..$];
	writeln(`Content:\n` ~ content);

	//... work with XML
	return groupNames;
}



More information about the Digitalmars-d-learn mailing list