1 // TortoiseMerge - a Diff/Patch program
\r
3 // Copyright (C) 2006-2007 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
22 // A template class to make an array which looks like a CStringArray or CDWORDArray but
\r
23 // is in fact based on a STL array, which is much faster at large sizes
\r
24 template <typename T> class CStdArray
\r
27 int GetCount() const { return (int)m_vec.size(); }
\r
28 const T& GetAt(int index) const { return m_vec[index]; }
\r
29 void RemoveAt(int index) { m_vec.erase(m_vec.begin()+index); }
\r
30 void InsertAt(int index, const T& strVal) { m_vec.insert(m_vec.begin()+index, strVal); }
\r
31 void InsertAt(int index, const T& strVal, int nCopies) { m_vec.insert(m_vec.begin()+index, nCopies, strVal); }
\r
32 void SetAt(int index, const T& strVal) { m_vec[index] = strVal; }
\r
33 void Add(const T& strVal) { m_vec.push_back(strVal); }
\r
34 void RemoveAll() { m_vec.clear(); }
\r
35 void Reserve(int lengthHint) { m_vec.reserve(lengthHint); }
\r
38 std::vector<T> m_vec;
\r
41 typedef CStdArray<CString> CStdCStringArray;
\r
42 typedef CStdArray<DWORD> CStdDWORDArray;
\r
45 * \ingroup TortoiseMerge
\r
47 * Represents an array of text lines which are read from a file.
\r
48 * This class is also responsible for determining the encoding of
\r
49 * the file (e.g. UNICODE, UTF8, ASCII, ...).
\r
51 class CFileTextLines : public CStdCStringArray
\r
54 CFileTextLines(void);
\r
55 ~CFileTextLines(void);
\r
68 * Loads the text file and adds each line to the array
\r
69 * \param sFilePath the path to the file
\r
71 BOOL Load(const CString& sFilePath, int lengthHint = 0);
\r
73 * Saves the whole array of text lines to a file, preserving
\r
74 * the line endings detected at Load()
\r
75 * \param sFilePath the path to save the file to
\r
77 BOOL Save(const CString& sFilePath, bool bSaveAsUTF8, DWORD dwIgnoreWhitespaces=0, BOOL bIgnoreCase = FALSE, bool bBlame = false);
\r
79 * Returns an error string of the last failed operation
\r
81 CString GetErrorString() const {return m_sErrorString;}
\r
83 * Copies the settings of a file like the line ending styles
\r
84 * to another CFileTextLines object.
\r
86 void CopySettings(CFileTextLines * pFileToCopySettingsTo);
\r
88 CFileTextLines::UnicodeType GetUnicodeType() const {return m_UnicodeType;}
\r
89 EOL GetLineEndings() const {return m_LineEndings;}
\r
91 void Add(const CString& sLine, EOL ending) {CStdCStringArray::Add(sLine); m_endings.push_back(ending);}
\r
92 void RemoveAt(int index) {CStdCStringArray::RemoveAt(index); m_endings.erase(m_endings.begin()+index);}
\r
93 void InsertAt(int index, const CString& strVal, EOL ending) {CStdCStringArray::InsertAt(index, strVal); m_endings.insert(m_endings.begin()+index, ending);}
\r
95 EOL GetLineEnding(int index) {return m_endings[index];}
\r
96 void SetLineEnding(int index, EOL ending) {m_endings[index] = ending;}
\r
98 void RemoveAll() {CStdCStringArray::RemoveAll(); m_endings.clear();}
\r
101 * Checks the line endings in a text buffer
\r
102 * \param pBuffer pointer to the buffer containing text
\r
103 * \param cd size of the text buffer in bytes
\r
105 EOL CheckLineEndings(LPVOID pBuffer, int cb);
\r
107 * Checks the Unicode type in a text buffer
\r
108 * \param pBuffer pointer to the buffer containing text
\r
109 * \param cd size of the text buffer in bytes
\r
111 CFileTextLines::UnicodeType CheckUnicodeType(LPVOID pBuffer, int cb);
\r
113 void SetErrorString();
\r
115 void StripAsciiWhiteSpace(CStringA& sLine);
\r
117 void StripWhiteSpace(CString& sLine,DWORD dwIgnoreWhitespaces, bool blame);
\r
118 void StripAsciiWhiteSpace(CStringA& sLine,DWORD dwIgnoreWhitespaces, bool blame);
\r
122 std::vector<EOL> m_endings;
\r
123 CString m_sErrorString;
\r
124 CFileTextLines::UnicodeType m_UnicodeType;
\r
126 bool m_bReturnAtEnd;
\r