X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14f355c2b5c71fc7c3d680aea366582d2ac60f7b..bf2c43c76e2819be443ab1d830ab68d9569d66b1:/src/common/textbuf.cpp diff --git a/src/common/textbuf.cpp b/src/common/textbuf.cpp index e77cf8be0d..406043e58e 100644 --- a/src/common/textbuf.cpp +++ b/src/common/textbuf.cpp @@ -3,7 +3,7 @@ // Purpose: implementation of wxTextBuffer class // Created: 14.11.01 // Author: Morten Hanssen, Vadim Zeitlin -// Copyright: (c) 1998-2001 wxWindows team +// Copyright: (c) 1998-2001 wxWidgets team // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -11,10 +11,6 @@ // headers // ============================================================================ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "textbuf.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -38,18 +34,13 @@ // ---------------------------------------------------------------------------- // default type is the native one -// the native type under Mac OS X is: -// - Unix when compiling with the Apple Developer Tools (__UNIX__) -// - Mac when compiling with CodeWarrior (__WXMAC__) const wxTextFileType wxTextBuffer::typeDefault = #if defined(__WINDOWS__) || defined(__DOS__) wxTextFileType_Dos; #elif defined(__UNIX__) wxTextFileType_Unix; -#elif defined(__WXMAC__) - wxTextFileType_Mac; -#elif defined(__WXPM__) +#elif defined(__OS2__) wxTextFileType_Os2; #else wxTextFileType_None; @@ -63,7 +54,7 @@ const wxChar *wxTextBuffer::GetEOL(wxTextFileType type) wxFAIL_MSG(wxT("bad buffer type in wxTextBuffer::GetEOL.")); // fall through nevertheless - we must return something... - case wxTextFileType_None: return wxT(""); + case wxTextFileType_None: return wxEmptyString; case wxTextFileType_Unix: return wxT("\n"); case wxTextFileType_Dos: return wxT("\r\n"); case wxTextFileType_Mac: return wxT("\r"); @@ -77,41 +68,41 @@ wxString wxTextBuffer::Translate(const wxString& text, wxTextFileType type) return text; // nor if it is empty - if ( text.IsEmpty() ) + if ( text.empty() ) return text; wxString eol = GetEOL(type), result; // optimization: we know that the length of the new string will be about - // the same as the length of the old one, so prealloc memory to aviod + // the same as the length of the old one, so prealloc memory to avoid // unnecessary relocations result.Alloc(text.Len()); wxChar chLast = 0; - for ( const wxChar *pc = text.c_str(); *pc; pc++ ) + for ( wxString::const_iterator i = text.begin(); i != text.end(); ++i ) { - wxChar ch = *pc; + wxChar ch = *i; switch ( ch ) { - case _T('\n'): + case wxT('\n'): // Dos/Unix line termination result += eol; chLast = 0; break; - case _T('\r'): - if ( chLast == _T('\r') ) { + case wxT('\r'): + if ( chLast == wxT('\r') ) { // Mac empty line result += eol; } else { // just remember it: we don't know whether it is just "\r" // or "\r\n" yet - chLast = _T('\r'); + chLast = wxT('\r'); } break; default: - if ( chLast == _T('\r') ) { + if ( chLast == wxT('\r') ) { // Mac line termination result += eol; @@ -135,6 +126,8 @@ wxString wxTextBuffer::Translate(const wxString& text, wxTextFileType type) #if wxUSE_TEXTBUFFER +wxString wxTextBuffer::ms_eof; + // ---------------------------------------------------------------------------- // ctors & dtor // ---------------------------------------------------------------------------- @@ -143,11 +136,12 @@ wxTextBuffer::wxTextBuffer(const wxString& strBufferName) : m_strBufferName(strBufferName) { m_nCurLine = 0; - m_isOpened = FALSE; + m_isOpened = false; } wxTextBuffer::~wxTextBuffer() { + // required here for Darwin } // ---------------------------------------------------------------------------- @@ -169,33 +163,33 @@ bool wxTextBuffer::Create(const wxString& strBufferName) bool wxTextBuffer::Create() { // buffer name must be either given in ctor or in Create(const wxString&) - wxASSERT( !m_strBufferName.IsEmpty() ); + wxASSERT( !m_strBufferName.empty() ); // if the buffer already exists do nothing - if ( Exists() ) return FALSE; - + if ( Exists() ) return false; + if ( !OnOpen(m_strBufferName, WriteAccess) ) - return FALSE; + return false; OnClose(); - return TRUE; + return true; } -bool wxTextBuffer::Open(const wxString& strBufferName, wxMBConv& conv) +bool wxTextBuffer::Open(const wxString& strBufferName, const wxMBConv& conv) { m_strBufferName = strBufferName; return Open(conv); } -bool wxTextBuffer::Open(wxMBConv& conv) +bool wxTextBuffer::Open(const wxMBConv& conv) { // buffer name must be either given in ctor or in Open(const wxString&) - wxASSERT( !m_strBufferName.IsEmpty() ); + wxASSERT( !m_strBufferName.empty() ); // open buffer in read-only mode if ( !OnOpen(m_strBufferName, ReadAccess) ) - return FALSE; + return false; // read buffer into memory m_isOpened = OnRead(conv); @@ -218,7 +212,7 @@ wxTextFileType wxTextBuffer::GuessType() const // we take MAX_LINES_SCAN in the beginning, middle and the end of buffer #define MAX_LINES_SCAN (10) - size_t nCount = m_aLines.Count() / 3, + size_t nCount = m_aLines.GetCount() / 3, nScan = nCount > 3*MAX_LINES_SCAN ? MAX_LINES_SCAN : nCount / 3; #define AnalyseLine(n) \ @@ -226,7 +220,7 @@ wxTextFileType wxTextBuffer::GuessType() const case wxTextFileType_Unix: nUnix++; break; \ case wxTextFileType_Dos: nDos++; break; \ case wxTextFileType_Mac: nMac++; break; \ - default: wxFAIL_MSG(_("unknown line terminator")); \ + default: wxFAIL_MSG(wxT("unknown line terminator")); \ } size_t n; @@ -250,9 +244,7 @@ wxTextFileType wxTextBuffer::GuessType() const ? wxTextFileType_##t1 \ : wxTextFileType_##t2 - // Watcom C++ doesn't seem to be able to handle the macro - // VS: Watcom 11 doesn't have a problem... -#if !(defined(__WATCOMC__) && (__WATCOMC__ < 1100)) +#if !defined(__WATCOMC__) || wxCHECK_WATCOM_VERSION(1,4) if ( nDos > nUnix ) return GREATER_OF(Dos, Mac); else if ( nDos < nUnix ) @@ -272,18 +264,15 @@ wxTextFileType wxTextBuffer::GuessType() const bool wxTextBuffer::Close() { - m_aTypes.Clear(); - m_aLines.Clear(); - m_nCurLine = 0; - m_isOpened = FALSE; + Clear(); + m_isOpened = false; - return TRUE; + return true; } -bool wxTextBuffer::Write(wxTextFileType typeNew, wxMBConv& conv) +bool wxTextBuffer::Write(wxTextFileType typeNew, const wxMBConv& conv) { return OnWrite(typeNew, conv); } #endif // wxUSE_TEXTBUFFER -