add a GetUTF8File(...) method with a pt::WTextStream & content to the misc

This commit is contained in:
Tomasz Sowa 2023-07-04 22:59:57 +02:00
parent 08821eb440
commit bf79e46411
Signed by: tomasz.sowa
GPG Key ID: 662CC1438638588B
2 changed files with 38 additions and 2 deletions

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2021, Tomasz Sowa
* Copyright (c) 2008-2023, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -1162,6 +1162,38 @@ bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool cl
}
bool GetUTF8File(const wchar_t * file_path, pt::WTextStream & content, bool clear_content)
{
char file[WINIX_OS_PATH_SIZE];
std::ifstream get_file_content;
if( clear_content )
content.clear();
if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) )
return false;
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
if( !get_file_content )
return false;
/*
* we don't report any errors when converting from UTF8 to wide characters here
*/
pt::utf8_to_wide(get_file_content, content);
get_file_content.close();
return true;
}
bool GetUTF8File(const std::wstring & file_path, pt::WTextStream & content, bool clear_content)
{
return GetUTF8File(file_path.c_str(), content, clear_content);
}
bool GetBinaryFile(const wchar_t * file_path, BinaryPage & content, bool clear_content)
{

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2021, Tomasz Sowa
* Copyright (c) 2008-2023, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -664,6 +664,10 @@ bool RenameFile(const std::wstring & from, const std::wstring & to);
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content = true);
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content = true);
bool GetUTF8File(const wchar_t * file_path, pt::WTextStream & content, bool clear_content = true);
bool GetUTF8File(const std::wstring & file_path, pt::WTextStream & content, bool clear_content = true);
bool GetBinaryFile(const wchar_t * file_path, BinaryPage & content, bool clear_content = true);
bool GetBinaryFile(const std::wstring & file_path, BinaryPage & content, bool clear_content = true);