Exemplo n.º 1
0
bool PutFileContents(const Utf8String& utf8Filename, const Utf8String& content)
{
	FILE *stream = fopen_utf8(utf8Filename.c_str(), "wb");
	if(!stream) return false;
	fwrite(content.c_str(), content.length(),1, stream);
	fclose(stream);
	return true;
}
Exemplo n.º 2
0
bool ReadUtf8TextFile(Utf8String utf8Filename, Utf8String& data)
{
	FILE *stream = fopen_utf8(utf8Filename.c_str(), "rb");
	if(!stream) return false;
        long size = getFileSize(utf8Filename);
	unsigned char buf[3];
	fread(buf, 1, 3, stream);	


	if(buf[0] == 0xEF || buf[1] == 0xBB || buf[2] == 0xBF) // UTF8 Byte Order Mark (BOM)
	{	
		size -= 3;	
	}
	else if(buf[0] == 0xFF || buf[1] == 0xFE ) {
		// UTF-16LE encoding
		size -= 2;
		fseek( stream, 2L,  SEEK_SET );
		std::wstring res;
		int charCount = size/2;
		res.resize(charCount);
		size_t charsRead = fread(&res[0], 2, charCount, stream);	
		res[charsRead]=0;
		fclose(stream);
		data = WstringToUtf8(res);
		return true;
	} 
	else {
		// no BOM was found; seeking backward
		fseek( stream, 0L,  SEEK_SET );
	}
	data.resize(size + 1);
	size_t bytesRead = fread(&data[0], 1, size, stream);	
	data[bytesRead] = 0;
	fclose(stream);
	return true;
}
Exemplo n.º 3
0
int64_t stringToint64_t(const Utf8String fileName)
{
    return zstrtoll(fileName.c_str(), 0, 10 , 0);
}