CFile (Win32 API IO) Refactoring
1. Rename CFile to Win32_IO_File (plus some modification in class). 2. Add new method writeStr() in Win32_IO_File class to write "char*" & string. 3. Change method names of Utf8_16_Write class and make writeFile() method return accurate type (boolean). Close #10612pull/10616/head
parent
11b2dd0f6b
commit
682a8edafa
|
@ -115,19 +115,19 @@ generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath)
|
|||
|
||||
void writeFileContent(const TCHAR *file2write, const char *content2write)
|
||||
{
|
||||
CFile file(file2write, CFile::Mode::WRITE);
|
||||
Win32_IO_File file(file2write, Win32_IO_File::Mode::WRITE);
|
||||
|
||||
if (file.IsOpened())
|
||||
file.Write(content2write, static_cast<unsigned long>(strlen(content2write)));
|
||||
if (file.isOpened())
|
||||
file.writeStr(content2write);
|
||||
}
|
||||
|
||||
|
||||
void writeLog(const TCHAR *logFileName, const char *log2write)
|
||||
{
|
||||
CFile file(logFileName, CFile::Mode::APPEND);
|
||||
Win32_IO_File file(logFileName, Win32_IO_File::Mode::APPEND);
|
||||
|
||||
if (file.IsOpened())
|
||||
file.Write(log2write, static_cast<unsigned long>(strlen(log2write)));
|
||||
if (file.isOpened())
|
||||
file.writeStr(log2write);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file is part of Notepad++ project
|
||||
// Copyright (C)2021 Don HO <don.h@free.fr>
|
||||
// Copyright (C)2021 Pavel Nedev (pg.nedev@gmail.com)
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,7 +18,7 @@
|
|||
#include "FileInterface.h"
|
||||
|
||||
|
||||
CFile::CFile(const char *fname, Mode fmode) : _hMode(fmode)
|
||||
Win32_IO_File::Win32_IO_File(const char *fname, Mode fmode) : _hMode(fmode)
|
||||
{
|
||||
if (fname)
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ CFile::CFile(const char *fname, Mode fmode) : _hMode(fmode)
|
|||
}
|
||||
|
||||
|
||||
CFile::CFile(const wchar_t *fname, Mode fmode) : _hMode(fmode)
|
||||
Win32_IO_File::Win32_IO_File(const wchar_t *fname, Mode fmode) : _hMode(fmode)
|
||||
{
|
||||
if (fname)
|
||||
{
|
||||
|
@ -58,9 +58,9 @@ CFile::CFile(const wchar_t *fname, Mode fmode) : _hMode(fmode)
|
|||
}
|
||||
|
||||
|
||||
void CFile::Close()
|
||||
void Win32_IO_File::close()
|
||||
{
|
||||
if (IsOpened())
|
||||
if (isOpened())
|
||||
{
|
||||
if (_written)
|
||||
{
|
||||
|
@ -75,21 +75,21 @@ void CFile::Close()
|
|||
}
|
||||
|
||||
|
||||
int_fast64_t CFile::GetSize()
|
||||
int_fast64_t Win32_IO_File::getSize()
|
||||
{
|
||||
LARGE_INTEGER r;
|
||||
r.QuadPart = -1;
|
||||
|
||||
if (IsOpened())
|
||||
if (isOpened())
|
||||
::GetFileSizeEx(_hFile, &r);
|
||||
|
||||
return static_cast<int_fast64_t>(r.QuadPart);
|
||||
}
|
||||
|
||||
|
||||
unsigned long CFile::Read(void *rbuf, unsigned long buf_size)
|
||||
unsigned long Win32_IO_File::read(void *rbuf, unsigned long buf_size)
|
||||
{
|
||||
if (!IsOpened() || (rbuf == nullptr) || (buf_size == 0))
|
||||
if (!isOpened() || (rbuf == nullptr) || (buf_size == 0))
|
||||
return 0;
|
||||
|
||||
DWORD bytes_read = 0;
|
||||
|
@ -100,10 +100,9 @@ unsigned long CFile::Read(void *rbuf, unsigned long buf_size)
|
|||
return bytes_read;
|
||||
}
|
||||
|
||||
|
||||
bool CFile::Write(const void *wbuf, unsigned long buf_size)
|
||||
bool Win32_IO_File::write(const void *wbuf, unsigned long buf_size)
|
||||
{
|
||||
if (!IsOpened() || (wbuf == nullptr) || (buf_size == 0) || ((_hMode != Mode::WRITE) && (_hMode != Mode::APPEND)))
|
||||
if (!isOpened() || (wbuf == nullptr) || (buf_size == 0) || ((_hMode != Mode::WRITE) && (_hMode != Mode::APPEND)))
|
||||
return false;
|
||||
|
||||
DWORD bytes_written = 0;
|
||||
|
@ -119,7 +118,7 @@ bool CFile::Write(const void *wbuf, unsigned long buf_size)
|
|||
|
||||
|
||||
// Helper function to auto-fill CreateFile params optimized for Notepad++ usage.
|
||||
void CFile::fillCreateParams(DWORD &access, DWORD &share, DWORD &disp, DWORD &attrib)
|
||||
void Win32_IO_File::fillCreateParams(DWORD &access, DWORD &share, DWORD &disp, DWORD &attrib)
|
||||
{
|
||||
access = GENERIC_READ;
|
||||
attrib = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_POSIX_SEMANTICS; // Distinguish between upper/lower case in name
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file is part of Notepad++ project
|
||||
// Copyright (C)2021 Don HO <don.h@free.fr>
|
||||
// Copyright (C)2021 Pavel Nedev (pg.nedev@gmail.com)
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,47 +18,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
#include <tchar.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
class CFile
|
||||
class Win32_IO_File final
|
||||
{
|
||||
public:
|
||||
enum class Mode
|
||||
{
|
||||
enum class Mode {
|
||||
READ,
|
||||
WRITE,
|
||||
APPEND
|
||||
};
|
||||
|
||||
CFile(const char *fname, Mode fmode = Mode::READ);
|
||||
CFile(const wchar_t *fname, Mode fmode = Mode::READ);
|
||||
Win32_IO_File(const char *fname, Mode fmode = Mode::READ);
|
||||
Win32_IO_File(const wchar_t *fname, Mode fmode = Mode::READ);
|
||||
|
||||
~CFile()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
Win32_IO_File() = delete;
|
||||
Win32_IO_File(const Win32_IO_File&) = delete;
|
||||
Win32_IO_File& operator=(const Win32_IO_File&) = delete;
|
||||
|
||||
bool IsOpened()
|
||||
{
|
||||
~Win32_IO_File() {
|
||||
close();
|
||||
};
|
||||
|
||||
bool isOpened() {
|
||||
return (_hFile != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
};
|
||||
|
||||
void Close();
|
||||
void close();
|
||||
int_fast64_t getSize();
|
||||
unsigned long read(void *rbuf, unsigned long buf_size);
|
||||
bool write(const void *wbuf, unsigned long buf_size);
|
||||
|
||||
int_fast64_t GetSize();
|
||||
|
||||
unsigned long Read(void *rbuf, unsigned long buf_size);
|
||||
bool Write(const void *wbuf, unsigned long buf_size);
|
||||
bool writeStr(const std::string& str) {
|
||||
return write(str.c_str(), static_cast<unsigned long>(str.length()));
|
||||
};
|
||||
|
||||
private:
|
||||
CFile(const CFile&) = delete;
|
||||
CFile& operator=(const CFile&) = delete;
|
||||
|
||||
void fillCreateParams(DWORD &access, DWORD &share, DWORD &disp, DWORD &attrib);
|
||||
|
||||
HANDLE _hFile {INVALID_HANDLE_VALUE};
|
||||
Mode _hMode {Mode::READ};
|
||||
bool _written {false};
|
||||
|
||||
void fillCreateParams(DWORD& access, DWORD& share, DWORD& disp, DWORD& attrib);
|
||||
};
|
||||
|
|
|
@ -869,16 +869,17 @@ bool FileManager::backupCurrentBuffer()
|
|||
::SetFileAttributes(fullpath, dwFileAttribs);
|
||||
}
|
||||
|
||||
if (UnicodeConvertor.fopen(fullpath))
|
||||
if (UnicodeConvertor.openFile(fullpath))
|
||||
{
|
||||
int lengthDoc = _pNotepadPlus->_pEditView->getCurrentDocLen();
|
||||
char* buf = (char*)_pNotepadPlus->_pEditView->execute(SCI_GETCHARACTERPOINTER); //to get characters directly from Scintilla buffer
|
||||
long items_written = 0;
|
||||
boolean isWrittenSuccessful = false;
|
||||
|
||||
if (encoding == -1) //no special encoding; can be handled directly by Utf8_16_Write
|
||||
{
|
||||
items_written = UnicodeConvertor.fwrite(buf, static_cast<unsigned long>(lengthDoc));
|
||||
isWrittenSuccessful = UnicodeConvertor.writeFile(buf, static_cast<unsigned long>(lengthDoc));
|
||||
if (lengthDoc == 0)
|
||||
items_written = 1;
|
||||
isWrittenSuccessful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -894,15 +895,14 @@ bool FileManager::backupCurrentBuffer()
|
|||
int incompleteMultibyteChar = 0;
|
||||
const char *newData = wmc.encode(SC_CP_UTF8, encoding, buf+i, grabSize, &newDataLen, &incompleteMultibyteChar);
|
||||
grabSize -= incompleteMultibyteChar;
|
||||
items_written = UnicodeConvertor.fwrite(newData, static_cast<unsigned long>(newDataLen));
|
||||
isWrittenSuccessful = UnicodeConvertor.writeFile(newData, static_cast<unsigned long>(newDataLen));
|
||||
}
|
||||
if (lengthDoc == 0)
|
||||
items_written = 1;
|
||||
isWrittenSuccessful = true;
|
||||
}
|
||||
UnicodeConvertor.fclose();
|
||||
UnicodeConvertor.closeFile();
|
||||
|
||||
// Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS.
|
||||
if (items_written == 1) // backup file has been saved
|
||||
if (isWrittenSuccessful) // backup file has been saved
|
||||
{
|
||||
buffer->setModifiedStatus(false);
|
||||
result = true; //all done
|
||||
|
@ -993,18 +993,19 @@ SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool i
|
|||
|
||||
int encoding = buffer->getEncoding();
|
||||
|
||||
if (UnicodeConvertor.fopen(fullpath))
|
||||
if (UnicodeConvertor.openFile(fullpath))
|
||||
{
|
||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, buffer->_doc); //generate new document
|
||||
|
||||
int lengthDoc = _pscratchTilla->getCurrentDocLen();
|
||||
char* buf = (char*)_pscratchTilla->execute(SCI_GETCHARACTERPOINTER); //to get characters directly from Scintilla buffer
|
||||
long items_written = 0;
|
||||
boolean isWrittenSuccessful = false;
|
||||
|
||||
if (encoding == -1) //no special encoding; can be handled directly by Utf8_16_Write
|
||||
{
|
||||
items_written = UnicodeConvertor.fwrite(buf, static_cast<unsigned long>(lengthDoc));
|
||||
isWrittenSuccessful = UnicodeConvertor.writeFile(buf, static_cast<unsigned long>(lengthDoc));
|
||||
if (lengthDoc == 0)
|
||||
items_written = 1;
|
||||
isWrittenSuccessful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1020,20 +1021,19 @@ SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool i
|
|||
int incompleteMultibyteChar = 0;
|
||||
const char *newData = wmc.encode(SC_CP_UTF8, encoding, buf+i, grabSize, &newDataLen, &incompleteMultibyteChar);
|
||||
grabSize -= incompleteMultibyteChar;
|
||||
items_written = UnicodeConvertor.fwrite(newData, static_cast<unsigned long>(newDataLen));
|
||||
isWrittenSuccessful = UnicodeConvertor.writeFile(newData, static_cast<unsigned long>(newDataLen));
|
||||
}
|
||||
if (lengthDoc == 0)
|
||||
items_written = 1;
|
||||
isWrittenSuccessful = true;
|
||||
}
|
||||
|
||||
// check the language du fichier
|
||||
LangType language = detectLanguageFromTextBegining((unsigned char *)buf, lengthDoc);
|
||||
|
||||
UnicodeConvertor.fclose();
|
||||
UnicodeConvertor.closeFile();
|
||||
|
||||
// Error, we didn't write the entire document to disk.
|
||||
// Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS.
|
||||
if (items_written != 1)
|
||||
if (!isWrittenSuccessful)
|
||||
{
|
||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
||||
return SavingStatus::SaveWrittingFailed;
|
||||
|
@ -1476,8 +1476,8 @@ BufferID FileManager::getBufferFromDocument(Document doc)
|
|||
|
||||
bool FileManager::createEmptyFile(const TCHAR * path)
|
||||
{
|
||||
CFile file(path, CFile::Mode::WRITE);
|
||||
return file.IsOpened();
|
||||
Win32_IO_File file(path, Win32_IO_File::Mode::WRITE);
|
||||
return file.isOpened();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -551,35 +551,24 @@ void TiXmlElement::SetAttribute( const TCHAR * name, const TCHAR * _value )
|
|||
}
|
||||
}
|
||||
|
||||
const char one_ws[] = " ";
|
||||
const char four_ws[] = " ";
|
||||
const char eol[] = "\r\n";
|
||||
|
||||
const generic_string tagOpenSymb = TEXT("<");
|
||||
const generic_string tagOpenSlash = TEXT("</");
|
||||
const generic_string tagCloseSymb = TEXT(">");
|
||||
|
||||
const char tagCloseChar[] = ">";
|
||||
const char tagCloseSymbFinal[] = " />";
|
||||
|
||||
void TiXmlElement::Print( CFile& cfile, int depth ) const
|
||||
void TiXmlElement::Print( Win32_IO_File& cfile, int depth ) const
|
||||
{
|
||||
int i;
|
||||
for ( i=0; i<depth; i++ )
|
||||
{
|
||||
cfile.Write(four_ws, 4);
|
||||
cfile.writeStr(" ");
|
||||
//generic_fprintf( cfile, TEXT(" ") );
|
||||
}
|
||||
|
||||
generic_string tagOpenValue = tagOpenSymb + value;
|
||||
std::string tagOpenValueA = wstring2string(tagOpenValue, CP_UTF8);
|
||||
cfile.Write(tagOpenValueA.c_str(), static_cast<unsigned long>(tagOpenValueA.length()));
|
||||
std::string tagOpenValue = "<";
|
||||
tagOpenValue += wstring2string(value, CP_UTF8);
|
||||
cfile.writeStr(tagOpenValue);
|
||||
//generic_fprintf( cfile, TEXT("<%ls"), value.c_str() );
|
||||
|
||||
TiXmlAttribute* attrib;
|
||||
for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
|
||||
{
|
||||
cfile.Write(one_ws, 1);
|
||||
cfile.writeStr(" ");
|
||||
//generic_fprintf(cfile, TEXT(" "));
|
||||
|
||||
attrib->Print( cfile, depth );
|
||||
|
@ -592,45 +581,45 @@ void TiXmlElement::Print( CFile& cfile, int depth ) const
|
|||
TiXmlNode* node;
|
||||
if ( !firstChild )
|
||||
{
|
||||
cfile.Write(tagCloseSymbFinal, 3);
|
||||
cfile.writeStr(" />");
|
||||
//generic_fprintf( cfile, TEXT(" />") );
|
||||
}
|
||||
else if ( firstChild == lastChild && firstChild->ToText() )
|
||||
{
|
||||
cfile.Write(tagCloseChar, 1);
|
||||
cfile.writeStr(">");
|
||||
//generic_fprintf( cfile, TEXT(">") );
|
||||
|
||||
firstChild->Print( cfile, depth + 1 );
|
||||
|
||||
generic_string tagCloseWithValue = tagOpenSlash + value + tagCloseSymb;
|
||||
std::string tagCloseWithValueA = wstring2string(tagCloseWithValue, CP_UTF8);
|
||||
cfile.Write(tagCloseWithValueA.c_str(), static_cast<unsigned long>(tagCloseWithValueA.length()));
|
||||
std::string tagCloseWithValue = "</";
|
||||
tagCloseWithValue += wstring2string(value, CP_UTF8) + ">";
|
||||
cfile.writeStr(tagCloseWithValue);
|
||||
//generic_fprintf( cfile, TEXT("</%ls>"), value.c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
cfile.Write(tagCloseChar, 1);
|
||||
cfile.writeStr(">");
|
||||
//generic_fprintf( cfile, TEXT(">") );
|
||||
|
||||
for ( node = firstChild; node; node=node->NextSibling() )
|
||||
{
|
||||
if ( !node->ToText() )
|
||||
{
|
||||
cfile.Write(eol, 2);
|
||||
cfile.writeStr("\r\n");
|
||||
//generic_fprintf( cfile, TEXT("\n") );
|
||||
}
|
||||
node->Print( cfile, depth+1 );
|
||||
}
|
||||
cfile.Write(eol, 2);
|
||||
cfile.writeStr("\r\n");
|
||||
//generic_fprintf( cfile, TEXT("\n") );
|
||||
|
||||
for( i=0; i<depth; ++i )
|
||||
cfile.Write(four_ws, 4);
|
||||
cfile.writeStr(" ");
|
||||
// generic_fprintf( cfile, TEXT(" ") );
|
||||
|
||||
generic_string tagCloseWithValue = tagOpenSlash + value + tagCloseSymb;
|
||||
std::string tagCloseWithValueA = wstring2string(tagCloseWithValue, CP_UTF8);
|
||||
cfile.Write(tagCloseWithValueA.c_str(), static_cast<unsigned long>(tagCloseWithValueA.length()));
|
||||
std::string tagCloseWithValue = "</";
|
||||
tagCloseWithValue += wstring2string(value, CP_UTF8) + ">";
|
||||
cfile.writeStr(tagCloseWithValue);
|
||||
//generic_fprintf( cfile, TEXT("</%ls>"), value.c_str() );
|
||||
}
|
||||
}
|
||||
|
@ -747,7 +736,7 @@ bool TiXmlDocument::LoadFile( const TCHAR* filename )
|
|||
|
||||
if ( file )
|
||||
{
|
||||
// Get the file size, so we can pre-allocate the generic_string. HUGE speed impact.
|
||||
// Get the file size, so we can pre-allocate the string. HUGE speed impact.
|
||||
long length = 0;
|
||||
fseek( file, 0, SEEK_END );
|
||||
length = ftell( file );
|
||||
|
@ -800,9 +789,9 @@ bool TiXmlDocument::SaveFile( const TCHAR * filename ) const
|
|||
return false;
|
||||
*/
|
||||
|
||||
CFile file(filename, CFile::Mode::WRITE);
|
||||
Win32_IO_File file(filename, Win32_IO_File::Mode::WRITE);
|
||||
|
||||
if (file.IsOpened())
|
||||
if (file.isOpened())
|
||||
{
|
||||
Print(file, 0);
|
||||
return true;
|
||||
|
@ -831,14 +820,14 @@ TiXmlNode* TiXmlDocument::Clone() const
|
|||
}
|
||||
|
||||
|
||||
void TiXmlDocument::Print( CFile& cfile, int depth ) const
|
||||
void TiXmlDocument::Print( Win32_IO_File& cfile, int depth ) const
|
||||
{
|
||||
TiXmlNode* node;
|
||||
for ( node=FirstChild(); node; node=node->NextSibling() )
|
||||
{
|
||||
node->Print( cfile, depth );
|
||||
|
||||
cfile.Write(eol, 2);
|
||||
cfile.writeStr("\r\n");
|
||||
//generic_fprintf( cfile, TEXT("\n") );
|
||||
}
|
||||
}
|
||||
|
@ -879,30 +868,29 @@ TiXmlAttribute* TiXmlAttribute::Previous() const
|
|||
}
|
||||
|
||||
|
||||
void TiXmlAttribute::Print( CFile& cfile, int /*depth*/ ) const
|
||||
void TiXmlAttribute::Print( Win32_IO_File& cfile, int /*depth*/ ) const
|
||||
{
|
||||
TIXML_STRING n, v;
|
||||
|
||||
PutString( Name(), &n );
|
||||
PutString( Value(), &v );
|
||||
|
||||
generic_string attrVsValue = n;
|
||||
std::string attrVsValue = wstring2string(n, CP_UTF8);
|
||||
if (value.find('\"') == TIXML_STRING::npos)
|
||||
{
|
||||
attrVsValue += TEXT("=\"");
|
||||
attrVsValue += v;
|
||||
attrVsValue += TEXT("\"");
|
||||
attrVsValue += "=\"";
|
||||
attrVsValue += wstring2string(v, CP_UTF8);
|
||||
attrVsValue += "\"";
|
||||
//generic_fprintf(cfile, TEXT("%ls=\"%ls\""), n.c_str(), v.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
attrVsValue += TEXT("='");
|
||||
attrVsValue += v;
|
||||
attrVsValue += TEXT("'");
|
||||
attrVsValue += "='";
|
||||
attrVsValue += wstring2string(v, CP_UTF8);
|
||||
attrVsValue += "'";
|
||||
//generic_fprintf(cfile, TEXT("%ls='%ls'"), n.c_str(), v.c_str());
|
||||
}
|
||||
std::string attrVsValueA = wstring2string(attrVsValue, CP_UTF8);
|
||||
cfile.Write(attrVsValueA.c_str(), static_cast<unsigned long>(attrVsValueA.length()));
|
||||
cfile.writeStr(attrVsValue);
|
||||
}
|
||||
|
||||
|
||||
|
@ -962,19 +950,18 @@ const double TiXmlAttribute::DoubleValue() const
|
|||
return generic_atof (value.c_str ());
|
||||
}
|
||||
|
||||
void TiXmlComment::Print( CFile& cfile, int depth ) const
|
||||
void TiXmlComment::Print( Win32_IO_File& cfile, int depth ) const
|
||||
{
|
||||
for ( int i=0; i<depth; i++ )
|
||||
{
|
||||
cfile.Write(four_ws, 4);
|
||||
cfile.writeStr(" ");
|
||||
//generic_fprintf( cfile, TEXT(" ") );
|
||||
}
|
||||
|
||||
generic_string comment = TEXT("<!--");
|
||||
comment += value;
|
||||
comment += TEXT("-->");
|
||||
std::string commentA = wstring2string(comment, CP_UTF8);
|
||||
cfile.Write(commentA.c_str(), static_cast<unsigned long>(commentA.length()));
|
||||
std::string comment = "<!--";
|
||||
comment += wstring2string(value, CP_UTF8);
|
||||
comment += "-->";
|
||||
cfile.writeStr(comment);
|
||||
//generic_fprintf( cfile, TEXT("<!--%ls-->"), value.c_str() );
|
||||
}
|
||||
|
||||
|
@ -997,13 +984,12 @@ TiXmlNode* TiXmlComment::Clone() const
|
|||
}
|
||||
|
||||
|
||||
void TiXmlText::Print( CFile& cfile, int /*depth*/ ) const
|
||||
void TiXmlText::Print( Win32_IO_File& cfile, int /*depth*/ ) const
|
||||
{
|
||||
TIXML_STRING buffer;
|
||||
PutString( value, &buffer );
|
||||
|
||||
std::string bufferA = wstring2string(buffer, CP_UTF8);
|
||||
cfile.Write(bufferA.c_str(), static_cast<unsigned long>(bufferA.length()));
|
||||
cfile.writeStr(wstring2string(buffer, CP_UTF8));
|
||||
//generic_fprintf( cfile, TEXT("%ls"), buffer.c_str() );
|
||||
}
|
||||
|
||||
|
@ -1037,43 +1023,38 @@ TiXmlDeclaration::TiXmlDeclaration( const TCHAR * _version,
|
|||
standalone = _standalone;
|
||||
}
|
||||
|
||||
const generic_string xmlDclOpen = TEXT("<?xml ");
|
||||
const generic_string xmlDclClose = TEXT("?>");
|
||||
|
||||
|
||||
void TiXmlDeclaration::Print( CFile& cfile, int /*depth*/ ) const
|
||||
void TiXmlDeclaration::Print( Win32_IO_File& cfile, int /*depth*/ ) const
|
||||
{
|
||||
generic_string xmlDcl = xmlDclOpen;
|
||||
std::string xmlDcl = "<?xml ";
|
||||
//generic_fprintf (cfile, TEXT("<?xml "));
|
||||
|
||||
if (!version.empty())
|
||||
{
|
||||
xmlDcl += TEXT("version=\"");
|
||||
xmlDcl += version;
|
||||
xmlDcl += TEXT("\" ");
|
||||
xmlDcl += "version=\"";
|
||||
xmlDcl += wstring2string(version, CP_UTF8);
|
||||
xmlDcl += "\" ";
|
||||
//generic_fprintf(cfile, TEXT("version=\"%ls\" "), version.c_str());
|
||||
}
|
||||
|
||||
if (!encoding.empty())
|
||||
{
|
||||
xmlDcl += TEXT("encoding=\"");
|
||||
xmlDcl += encoding;
|
||||
xmlDcl += TEXT("\" ");
|
||||
xmlDcl += "encoding=\"";
|
||||
xmlDcl += wstring2string(encoding, CP_UTF8);
|
||||
xmlDcl += "\" ";
|
||||
//generic_fprintf(cfile, TEXT("encoding=\"%ls\" "), encoding.c_str());
|
||||
}
|
||||
if (!standalone.empty())
|
||||
{
|
||||
xmlDcl += TEXT("standalone=\"");
|
||||
xmlDcl += standalone;
|
||||
xmlDcl += TEXT("\" ");
|
||||
xmlDcl += "standalone=\"";
|
||||
xmlDcl += wstring2string(standalone, CP_UTF8);
|
||||
xmlDcl += "\" ";
|
||||
//generic_fprintf(cfile, TEXT("standalone=\"%ls\" "), standalone.c_str());
|
||||
}
|
||||
|
||||
xmlDcl += xmlDclClose;
|
||||
xmlDcl += "?>";
|
||||
//generic_fprintf (cfile, TEXT("?>"));
|
||||
|
||||
std::string xmlDclA = wstring2string(xmlDcl, CP_UTF8);
|
||||
cfile.Write(xmlDclA.c_str(), static_cast<unsigned long>(xmlDclA.length()));
|
||||
cfile.writeStr(xmlDcl);
|
||||
}
|
||||
|
||||
void TiXmlDeclaration::StreamOut( TIXML_OSTREAM * stream ) const
|
||||
|
@ -1116,14 +1097,13 @@ TiXmlNode* TiXmlDeclaration::Clone() const
|
|||
}
|
||||
|
||||
|
||||
void TiXmlUnknown::Print( CFile& cfile, int depth ) const
|
||||
void TiXmlUnknown::Print( Win32_IO_File& cfile, int depth ) const
|
||||
{
|
||||
for ( int i=0; i<depth; i++ )
|
||||
cfile.Write(four_ws, 4);
|
||||
cfile.writeStr(" ");
|
||||
//generic_fprintf( cfile, TEXT(" ") );
|
||||
|
||||
std::string valueA = wstring2string(value, CP_UTF8);
|
||||
cfile.Write(valueA.c_str(), static_cast<unsigned long>(valueA.length()));
|
||||
cfile.writeStr(wstring2string(value, CP_UTF8));
|
||||
//generic_fprintf( cfile, TEXT("%ls"), value.c_str() );
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ public:
|
|||
|
||||
(For an unformatted stream, use the << operator.)
|
||||
*/
|
||||
virtual void Print( CFile& cfile, int depth ) const = 0;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const = 0;
|
||||
|
||||
/** The world does not agree on whether white space should be kept or
|
||||
not. In order to make everyone happy, these global, static functions
|
||||
|
@ -640,7 +640,7 @@ public:
|
|||
virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data );
|
||||
|
||||
// [internal use]
|
||||
virtual void Print( CFile& cfile, int depth ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const;
|
||||
|
||||
virtual void StreamOut( TIXML_OSTREAM * out ) const;
|
||||
// [internal use]
|
||||
|
@ -784,7 +784,7 @@ public:
|
|||
virtual TiXmlNode* Clone() const;
|
||||
// [internal use]
|
||||
|
||||
virtual void Print( CFile& cfile, int depth ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -823,7 +823,7 @@ public:
|
|||
// [internal use] Creates a new Element and returs it.
|
||||
virtual TiXmlNode* Clone() const;
|
||||
// [internal use]
|
||||
virtual void Print( CFile& cfile, int depth ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const;
|
||||
protected:
|
||||
// used to be public
|
||||
#ifdef TIXML_USE_STL
|
||||
|
@ -860,7 +860,7 @@ public:
|
|||
#endif
|
||||
|
||||
// [internal use]
|
||||
virtual void Print( CFile& cfile, int depth ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const;
|
||||
|
||||
protected :
|
||||
// [internal use] Creates a new Element and returns it.
|
||||
|
@ -929,7 +929,7 @@ public:
|
|||
// [internal use] Creates a new Element and returs it.
|
||||
virtual TiXmlNode* Clone() const;
|
||||
// [internal use]
|
||||
virtual void Print( CFile& cfile, int depth ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const;
|
||||
|
||||
protected:
|
||||
// used to be public
|
||||
|
@ -964,7 +964,7 @@ public:
|
|||
// [internal use]
|
||||
virtual TiXmlNode* Clone() const;
|
||||
// [internal use]
|
||||
virtual void Print( CFile& cfile, int depth ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth ) const;
|
||||
protected:
|
||||
#ifdef TIXML_USE_STL
|
||||
virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
|
||||
|
@ -1101,7 +1101,7 @@ public:
|
|||
void Print() const { /*Print(stdout, 0);*/ }
|
||||
|
||||
// [internal use]
|
||||
virtual void Print( CFile& cfile, int depth = 0 ) const;
|
||||
virtual void Print( Win32_IO_File& cfile, int depth = 0 ) const;
|
||||
// [internal use]
|
||||
void SetError( int err, const TCHAR* errorLocation, TiXmlParsingData* prevData );
|
||||
|
||||
|
|
|
@ -285,17 +285,17 @@ Utf8_16_Write::Utf8_16_Write()
|
|||
|
||||
Utf8_16_Write::~Utf8_16_Write()
|
||||
{
|
||||
fclose();
|
||||
closeFile();
|
||||
}
|
||||
|
||||
bool Utf8_16_Write::fopen(const TCHAR *name)
|
||||
bool Utf8_16_Write::openFile(const TCHAR *name)
|
||||
{
|
||||
m_pFile = std::make_unique<CFile>(name, CFile::Mode::WRITE);
|
||||
m_pFile = std::make_unique<Win32_IO_File>(name, Win32_IO_File::Mode::WRITE);
|
||||
|
||||
if (!m_pFile)
|
||||
return false;
|
||||
|
||||
if (!m_pFile->IsOpened())
|
||||
if (!m_pFile->isOpened())
|
||||
{
|
||||
m_pFile = nullptr;
|
||||
return false;
|
||||
|
@ -306,12 +306,12 @@ bool Utf8_16_Write::fopen(const TCHAR *name)
|
|||
return true;
|
||||
}
|
||||
|
||||
unsigned long Utf8_16_Write::fwrite(const void* p, unsigned long _size)
|
||||
bool Utf8_16_Write::writeFile(const void* p, unsigned long _size)
|
||||
{
|
||||
// no file open
|
||||
if (!m_pFile)
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_bFirstWrite)
|
||||
|
@ -319,14 +319,14 @@ unsigned long Utf8_16_Write::fwrite(const void* p, unsigned long _size)
|
|||
switch (m_eEncoding)
|
||||
{
|
||||
case uniUTF8: {
|
||||
if (!m_pFile->Write(k_Boms[m_eEncoding], 3))
|
||||
return 0;
|
||||
if (!m_pFile->write(k_Boms[m_eEncoding], 3))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case uni16BE:
|
||||
case uni16LE:
|
||||
if (!m_pFile->Write(k_Boms[m_eEncoding], 2))
|
||||
return 0;
|
||||
if (!m_pFile->write(k_Boms[m_eEncoding], 2))
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
// nothing to do
|
||||
|
@ -335,7 +335,7 @@ unsigned long Utf8_16_Write::fwrite(const void* p, unsigned long _size)
|
|||
m_bFirstWrite = false;
|
||||
}
|
||||
|
||||
unsigned long ret = 0;
|
||||
bool isOK = false;
|
||||
|
||||
switch (m_eEncoding)
|
||||
{
|
||||
|
@ -344,8 +344,8 @@ unsigned long Utf8_16_Write::fwrite(const void* p, unsigned long _size)
|
|||
case uniCookie:
|
||||
case uniUTF8: {
|
||||
// Normal write
|
||||
if (m_pFile->Write(p, _size))
|
||||
ret = 1;
|
||||
if (m_pFile->write(p, _size))
|
||||
isOK = true;
|
||||
break;
|
||||
}
|
||||
case uni16BE_NoBOM:
|
||||
|
@ -365,18 +365,18 @@ unsigned long Utf8_16_Write::fwrite(const void* p, unsigned long _size)
|
|||
iter8.get(&buf [bufIndex++]);
|
||||
|
||||
if (bufIndex == bufSize || !iter8) {
|
||||
if (!m_pFile->Write(buf, bufIndex*sizeof(utf16))) return 0;
|
||||
if (!m_pFile->write(buf, bufIndex*sizeof(utf16))) return 0;
|
||||
bufIndex = 0;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
isOK = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return isOK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -448,7 +448,7 @@ void Utf8_16_Write::setEncoding(UniMode eType)
|
|||
}
|
||||
|
||||
|
||||
void Utf8_16_Write::fclose()
|
||||
void Utf8_16_Write::closeFile()
|
||||
{
|
||||
if (m_pNewBuf)
|
||||
{
|
||||
|
|
|
@ -139,16 +139,16 @@ public:
|
|||
|
||||
void setEncoding(UniMode eType);
|
||||
|
||||
bool fopen(const TCHAR *name);
|
||||
unsigned long fwrite(const void* p, unsigned long _size);
|
||||
void fclose();
|
||||
bool openFile(const TCHAR *name);
|
||||
bool writeFile(const void* p, unsigned long _size);
|
||||
void closeFile();
|
||||
|
||||
size_t convert(char* p, size_t _size);
|
||||
char* getNewBuf() { return reinterpret_cast<char*>(m_pNewBuf); }
|
||||
|
||||
protected:
|
||||
UniMode m_eEncoding;
|
||||
std::unique_ptr<CFile> m_pFile;
|
||||
std::unique_ptr<Win32_IO_File> m_pFile;
|
||||
ubyte* m_pNewBuf;
|
||||
size_t m_nBufSize;
|
||||
bool m_bFirstWrite;
|
||||
|
|
Loading…
Reference in New Issue