wxFAIL_MSG(wxT("bad file type in wxTextFile::GetEOL."));
// fall through nevertheless - we must return something...
- case wxTextFileType_None: return wxT(_T(""));
- case wxTextFileType_Unix: return wxT(_T("\n"));
- case wxTextFileType_Dos: return wxT(_T("\r\n"));
- case wxTextFileType_Mac: return wxT(_T("\r"));
+ case wxTextFileType_None: return wxT("");
+ case wxTextFileType_Unix: return wxT("\n");
+ case wxTextFileType_Dos: return wxT("\r\n");
+ case wxTextFileType_Mac: return wxT("\r");
}
}
if ( type == wxTextFileType_None )
return text;
+ // GRG: don't do anything either if it is empty
+ if ( text.IsEmpty() )
+ return text;
+
wxString eol = GetEOL(type), result;
// optimization: we know that the length of the new string will be about
if ( chLast == _T('\r') ) {
// Mac line termination
result += eol;
+
+ // reset chLast to avoid inserting another eol before the
+ // next character
+ chLast = 0;
}
// add to the current line
return wxFile::Exists(m_strFile);
}
+bool wxTextFile::Create(const wxString& strFile)
+{
+ m_strFile = strFile;
+
+ return Create();
+}
+
+bool wxTextFile::Create()
+{
+ // file name must be either given in ctor or in Create(const wxString&)
+ wxASSERT( !m_strFile.IsEmpty() );
+
+ // if the file already exists do nothing
+ if ( Exists() ) return FALSE;
+
+ if ( m_file.Open(m_strFile, wxFile::write) )
+ {
+ m_file.Close();
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
bool wxTextFile::Open(const wxString& strFile)
{
m_strFile = strFile;
char ch, chLast = '\0';
char buf[1024];
int n, nRead;
- while ( !m_file.Eof() ) {
+ do {
nRead = m_file.Read(buf, WXSIZEOF(buf));
if ( nRead == wxInvalidOffset ) {
// read error (error message already given in wxFile::Read)
}
}
}
- }
+ } while ( nRead == WXSIZEOF(buf) );
// anything in the last line?
if ( !str.IsEmpty() ) {