add a GetUTF8File(...) method with a pt::WTextStream & content to the misc
This commit is contained in:
parent
08821eb440
commit
bf79e46411
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue