Revision: 5735
http://winmerge.svn.sourceforge.net/winmerge/?rev=5735&view=rev
Author: kimmov
Date: 2008-08-04 20:54:49 +0000 (Mon, 04 Aug 2008)
Log Message:
-----------
Rename SLineInfo to LineInfo and make it a class. Add LineInfo methods Create(), CreateEmpty() and Append().
Modified Paths:
--------------
trunk/Src/Merge.vcproj
trunk/Src/editlib/LineInfo.h
trunk/Src/editlib/ccrystaltextbuffer.cpp
trunk/Src/editlib/ccrystaltextbuffer.h
Added Paths:
-----------
trunk/Src/editlib/LineInfo.cpp
Modified: trunk/Src/Merge.vcproj
===================================================================
--- trunk/Src/Merge.vcproj 2008-08-04 15:38:15 UTC (rev 5734)
+++ trunk/Src/Merge.vcproj 2008-08-04 20:54:49 UTC (rev 5735)
@@ -7654,6 +7654,43 @@
</FileConfiguration>
</File>
<File
+ RelativePath=".\editlib\LineInfo.cpp">
+ <FileConfiguration
+ Name="UnicodeRelease|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="UnicodeDebug|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ BrowseInformation="1"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ BrowseInformation="1"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""/>
+ </FileConfiguration>
+ </File>
+ <File
RelativePath="editlib\LineInfo.h">
</File>
<File
@@ -8409,9 +8446,6 @@
</FileConfiguration>
</File>
<File
- RelativePath="editlib\UndoRecord.h">
- </File>
- <File
RelativePath="editlib\UndoRecord.cpp">
<FileConfiguration
Name="UnicodeRelease|Win32">
@@ -8449,6 +8483,9 @@
</FileConfiguration>
</File>
<File
+ RelativePath="editlib\UndoRecord.h">
+ </File>
+ <File
RelativePath="editlib\wispelld.h">
</File>
<File
Added: trunk/Src/editlib/LineInfo.cpp
===================================================================
--- trunk/Src/editlib/LineInfo.cpp (rev 0)
+++ trunk/Src/editlib/LineInfo.cpp 2008-08-04 20:54:49 UTC (rev 5735)
@@ -0,0 +1,91 @@
+/**
+ * @file LineInfo.cpp
+ *
+ * @brief Implementation of LineInfo class.
+ */
+// ID line follows -- this is updated by SVN
+// $Id$
+
+#include "stdafx.h"
+#include "LineInfo.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/**
+ * @brief Create a line.
+ * @param [in] pszLine Line data.
+ * @param [in] nLength Line length.
+ */
+void LineInfo::Create(LPCTSTR pszLine, int nLength)
+{
+ m_nLength = nLength;
+ m_nMax = ALIGN_BUF_SIZE (m_nLength + 1);
+ ASSERT (m_nMax >= m_nLength + 1);
+ m_pcLine = new TCHAR[m_nMax];
+ if (m_nLength > 0)
+ {
+ DWORD dwLen = sizeof (TCHAR) * m_nLength;
+ CopyMemory (m_pcLine, pszLine, dwLen);
+ }
+ m_pcLine[m_nLength] = '\0';
+
+ int nEols = 0;
+ if (nLength > 1 && IsDosEol(&pszLine[nLength - 2]))
+ nEols = 2;
+ else if (nLength && IsEol(pszLine[nLength - 1]))
+ nEols = 1;
+ m_nLength -= nEols;
+ m_nEolChars = nEols;
+}
+
+/**
+ * @brief Create an empty line.
+ */
+void LineInfo::CreateEmpty()
+{
+ m_nLength = 0;
+ m_nEolChars = 0;
+ m_nMax = ALIGN_BUF_SIZE (m_nLength + 1);
+ m_pcLine = new TCHAR[m_nMax];
+ m_pcLine[0] = '\0';
+}
+
+/**
+ * @brief Append a text to the line.
+ * @param [in] pszChars String to append to the line.
+ * @param [in] nLength Length of the string to append.
+ */
+void LineInfo::Append(LPCTSTR pszChars, int nLength)
+{
+ int nBufNeeded = m_nLength + nLength + 1;
+ if (nBufNeeded > m_nMax)
+ {
+ m_nMax = ALIGN_BUF_SIZE (nBufNeeded);
+ ASSERT (m_nMax >= m_nLength + nLength);
+ TCHAR *pcNewBuf = new TCHAR[m_nMax];
+ if (FullLength() > 0)
+ memcpy (pcNewBuf, m_pcLine, sizeof (TCHAR) * (FullLength() + 1));
+ delete[] m_pcLine;
+ m_pcLine = pcNewBuf;
+ }
+
+ memcpy (m_pcLine + m_nLength, pszChars, sizeof (TCHAR) * nLength);
+ m_nLength += nLength;
+ m_pcLine[m_nLength] = '\0';
+
+ // Did line gain eol ? (We asserted above that it had none at start)
+ if (nLength > 1 && IsDosEol(&m_pcLine[m_nLength - 2]))
+ {
+ m_nEolChars = 2;
+ }
+ else if (LineInfo::IsEol(m_pcLine[m_nLength - 1]))
+ {
+ m_nEolChars = 1;
+ }
+ m_nLength -= m_nEolChars;
+ ASSERT (m_nLength + m_nEolChars <= m_nMax);
+}
Property changes on: trunk/Src/editlib/LineInfo.cpp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/Src/editlib/LineInfo.h
===================================================================
--- trunk/Src/editlib/LineInfo.h 2008-08-04 15:38:15 UTC (rev 5734)
+++ trunk/Src/editlib/LineInfo.h 2008-08-04 20:54:49 UTC (rev 5735)
@@ -1,7 +1,7 @@
/**
* @file LineInfo.h
*
- * @brief Declaration for SLineInfo structure.
+ * @brief Declaration for LineInfo class.
*
*/
// ID line follows -- this is updated by SVN
@@ -10,12 +10,17 @@
#ifndef _EDITOR_LINEINFO_H_
#define _EDITOR_LINEINFO_H_
+// Line allocation granularity
+#define CHAR_ALIGN 16
+#define ALIGN_BUF_SIZE(size) ((size) / CHAR_ALIGN) * CHAR_ALIGN + CHAR_ALIGN;
+
/**
* @brief Line information.
- * This structure presents one line in the editor.
+ * This class presents one line in the editor.
*/
-struct SLineInfo
+class LineInfo
{
+public: // All public as this used to be a struct.
TCHAR *m_pcLine; /**< Line data. */
int m_nLength; /**< Line length (without EOL bytes). */
int m_nMax; /**< Allocated space for line data. */
@@ -25,11 +30,24 @@
int FullLength() const { return m_nLength+m_nEolChars; }
int Length() const { return m_nLength; }
+ void Create(LPCTSTR pszLine, int nLength);
+ void CreateEmpty();
+ void Append(LPCTSTR pszChars, int nLength);
- SLineInfo ()
+ LineInfo ()
{
- memset (this, 0, sizeof (SLineInfo));
+ memset (this, 0, sizeof (LineInfo));
};
+
+ static bool IsEol(TCHAR ch)
+ {
+ return ch=='\r' || ch=='\n';
+ };
+
+ static bool IsDosEol(LPCTSTR sz)
+ {
+ return sz[0]=='\r' && sz[1]=='\n';
+ };
};
#endif // _EDITOR_LINEINFO_H_
Modified: trunk/Src/editlib/ccrystaltextbuffer.cpp
===================================================================
--- trunk/Src/editlib/ccrystaltextbuffer.cpp 2008-08-04 15:38:15 UTC (rev 5734)
+++ trunk/Src/editlib/ccrystaltextbuffer.cpp 2008-08-04 20:54:49 UTC (rev 5735)
@@ -87,10 +87,6 @@
using namespace std;
-// Line allocation granularity
-#define CHAR_ALIGN 16
-#define ALIGN_BUF_SIZE(size) ((size) / CHAR_ALIGN) * CHAR_ALIGN + CHAR_ALIGN;
-
const TCHAR crlf[] = _T ("\r\n");
#ifdef _DEBUG
@@ -187,16 +183,6 @@
/////////////////////////////////////////////////////////////////////////////
// CCrystalTextBuffer message handlers
-static bool iseol(TCHAR ch)
-{
- return ch=='\r' || ch=='\n';
-}
-
-static bool isdoseol(LPCTSTR sz)
-{
- return sz[0]=='\r' && sz[1]=='\n';
-}
-
/**
* @brief Insert the same line once or several times
*
@@ -207,26 +193,9 @@
{
ASSERT(nLength != -1);
- SLineInfo li;
- li.m_nLength = nLength;
- li.m_nMax = ALIGN_BUF_SIZE (li.m_nLength + 1);
- ASSERT (li.m_nMax >= li.m_nLength + 1);
- li.m_pcLine = new TCHAR[li.m_nMax];
- if (li.m_nLength > 0)
- {
- DWORD dwLen = sizeof (TCHAR) * li.m_nLength;
- CopyMemory (li.m_pcLine, pszLine, dwLen);
- }
- li.m_pcLine[li.m_nLength] = '\0';
+ LineInfo li;
+ li.Create(pszLine, nLength);
- int nEols = 0;
- if (nLength>1 && isdoseol(&pszLine[nLength-2]))
- nEols = 2;
- else if (nLength && iseol(pszLine[nLength-1]))
- nEols = 1;
- li.m_nLength -= nEols;
- li.m_nEolChars = nEols;
-
// nPosition not defined ? Insert at end of array
if (nPosition == -1)
nPosition = (int) m_aLines.GetSize();
@@ -260,33 +229,8 @@
if (nLength == 0)
return;
- SLineInfo & li = m_aLines[nLineIndex];
- ASSERT(!li.m_nEolChars);
- int nBufNeeded = li.m_nLength + nLength+1;
- if (nBufNeeded > li.m_nMax)
- {
- li.m_nMax = ALIGN_BUF_SIZE (nBufNeeded);
- ASSERT (li.m_nMax >= li.m_nLength + nLength);
- TCHAR *pcNewBuf = new TCHAR[li.m_nMax];
- if (li.FullLength() > 0)
- memcpy (pcNewBuf, li.m_pcLine, sizeof (TCHAR) * (li.FullLength()+1));
- delete[] li.m_pcLine;
- li.m_pcLine = pcNewBuf;
- }
- memcpy (li.m_pcLine + li.m_nLength, pszChars, sizeof (TCHAR) * nLength);
- li.m_nLength += nLength;
- li.m_pcLine[li.m_nLength] = '\0';
- // Did line gain eol ? (We asserted above that it had none at start)
- if (nLength>1 && isdoseol(&li.m_pcLine[li.m_nLength-2]))
- {
- li.m_nEolChars = 2;
- }
- else if (iseol(li.m_pcLine[li.m_nLength-1]))
- {
- li.m_nEolChars = 1;
- }
- li.m_nLength -= li.m_nEolChars;
- ASSERT (li.m_nLength + li.m_nEolChars <= li.m_nMax);
+ LineInfo & li = m_aLines[nLineIndex];
+ li.Append(pszChars, nLength);
}
/**
@@ -329,18 +273,12 @@
void CCrystalTextBuffer::SetEmptyLine (int nPosition, int nCount /*= 1*/ )
{
- if (nCount > 0) {
- SLineInfo li;
- li.m_nLength = 0;
- li.m_nEolChars = 0;
- li.m_nMax = ALIGN_BUF_SIZE (li.m_nLength + 1);
- for (int ic = 0; ic < nCount; ic++)
- {
- m_aLines[nPosition+ic] = li;
- m_aLines[nPosition+ic].m_pcLine = new TCHAR[li.m_nMax];
- m_aLines[nPosition+ic].m_pcLine[0] = _T('\0');
- }
- }
+ for (int i = 0; i < nCount; i++)
+ {
+ LineInfo li;
+ li.CreateEmpty();
+ m_aLines[nPosition + i] = li;
+ }
}
void CCrystalTextBuffer::
@@ -775,7 +713,7 @@
BOOL CCrystalTextBuffer::
ChangeLineEol (int nLine, LPCTSTR lpEOL)
{
- SLineInfo & li = m_aLines[nLine];
+ LineInfo & li = m_aLines[nLine];
int nNewEolChars = (int) _tcslen(lpEOL);
if (nNewEolChars == li.m_nEolChars)
if (_tcscmp(li.m_pcLine + li.Length(), lpEOL) == 0)
@@ -1101,7 +1039,7 @@
if (nStartLine == nEndLine)
{
// delete part of one line
- SLineInfo & li = m_aLines[nStartLine];
+ LineInfo & li = m_aLines[nStartLine];
if (nEndChar < li.Length() || li.m_nEolChars)
{
// preserve characters after deleted range by shifting up
@@ -1153,7 +1091,7 @@
CString CCrystalTextBuffer::
StripTail (int i, int bytes)
{
- SLineInfo & li = m_aLines[i];
+ LineInfo & li = m_aLines[i];
// Must at least take off the EOL characters
ASSERT(bytes >= li.FullLength() - li.Length());
@@ -1218,7 +1156,7 @@
int haseol = 0;
nTextPos = 0;
// advance to end of line
- while (nTextPos < cchText && !iseol(pszText[nTextPos]))
+ while (nTextPos < cchText && !LineInfo::IsEol(pszText[nTextPos]))
nTextPos++;
// advance after EOL of line
if (nTextPos < cchText)
@@ -1226,7 +1164,7 @@
haseol = 1;
LPCTSTR eol = &pszText[nTextPos];
nTextPos++;
- if (nTextPos < cchText && isdoseol(eol))
+ if (nTextPos < cchText && LineInfo::IsDosEol(eol))
nTextPos++;
}
Modified: trunk/Src/editlib/ccrystaltextbuffer.h
===================================================================
--- trunk/Src/editlib/ccrystaltextbuffer.h 2008-08-04 15:38:15 UTC (rev 5734)
+++ trunk/Src/editlib/ccrystaltextbuffer.h 2008-08-04 20:54:49 UTC (rev 5735)
@@ -151,7 +151,7 @@
};
// Lines of text
- CArray < SLineInfo, SLineInfo & >m_aLines;
+ CArray < LineInfo, LineInfo & >m_aLines;
// Undo
std::vector<SUndoRecord> m_aUndoBuf; /**< Undo records. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|