Updated Tortoise.pot
[TortoiseGit.git] / src / TortoiseMerge / FileTextLines.h
blob9ce94393abe11f0d5fe1f81d43a8acfd3fc76208
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2007,2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include "EOL.h"
22 // A template class to make an array which looks like a CStringArray or CDWORDArray but
23 // is in fact based on a STL array, which is much faster at large sizes
24 template <typename T> class CStdArray
26 public:
27 int GetCount() const { return (int)m_vec.size(); }
28 const T& GetAt(int index) const { return m_vec[index]; }
29 void RemoveAt(int index) { m_vec.erase(m_vec.begin()+index); }
30 void InsertAt(int index, const T& strVal) { m_vec.insert(m_vec.begin()+index, strVal); }
31 void InsertAt(int index, const T& strVal, int nCopies) { m_vec.insert(m_vec.begin()+index, nCopies, strVal); }
32 void SetAt(int index, const T& strVal) { m_vec[index] = strVal; }
33 void Add(const T& strVal) { m_vec.push_back(strVal); }
34 void RemoveAll() { m_vec.clear(); }
35 void Reserve(int lengthHint) { m_vec.reserve(lengthHint); }
37 private:
38 std::vector<T> m_vec;
41 typedef CStdArray<CString> CStdCStringArray;
42 typedef CStdArray<DWORD> CStdDWORDArray;
44 /**
45 * \ingroup TortoiseMerge
47 * Represents an array of text lines which are read from a file.
48 * This class is also responsible for determining the encoding of
49 * the file (e.g. UNICODE, UTF8, ASCII, ...).
51 class CFileTextLines : public CStdCStringArray
53 public:
54 CFileTextLines(void);
55 ~CFileTextLines(void);
57 enum UnicodeType
59 AUTOTYPE,
60 BINARY,
61 ASCII,
62 UNICODE_LE,
63 UNICODE_BE,
64 UTF8,
65 UTF8BOM,
68 /**
69 * Loads the text file and adds each line to the array
70 * \param sFilePath the path to the file
72 BOOL Load(const CString& sFilePath, int lengthHint = 0);
73 /**
74 * Saves the whole array of text lines to a file, preserving
75 * the line endings detected at Load()
76 * \param sFilePath the path to save the file to
78 BOOL Save(const CString& sFilePath, bool bSaveAsUTF8, DWORD dwIgnoreWhitespaces=0, BOOL bIgnoreCase = FALSE, bool bBlame = false);
79 /**
80 * Returns an error string of the last failed operation
82 CString GetErrorString() const {return m_sErrorString;}
83 /**
84 * Copies the settings of a file like the line ending styles
85 * to another CFileTextLines object.
87 void CopySettings(CFileTextLines * pFileToCopySettingsTo);
89 CFileTextLines::UnicodeType GetUnicodeType() const {return m_UnicodeType;}
90 EOL GetLineEndings() const {return m_LineEndings;}
92 void Add(const CString& sLine, EOL ending) {CStdCStringArray::Add(sLine); m_endings.push_back(ending);}
93 void RemoveAt(int index) {CStdCStringArray::RemoveAt(index); m_endings.erase(m_endings.begin()+index);}
94 void InsertAt(int index, const CString& strVal, EOL ending) {CStdCStringArray::InsertAt(index, strVal); m_endings.insert(m_endings.begin()+index, ending);}
96 EOL GetLineEnding(int index) {return m_endings[index];}
97 void SetLineEnding(int index, EOL ending) {m_endings[index] = ending;}
99 void RemoveAll() {CStdCStringArray::RemoveAll(); m_endings.clear();}
102 * Checks the Unicode type in a text buffer
103 * \param pBuffer pointer to the buffer containing text
104 * \param cd size of the text buffer in bytes
106 CFileTextLines::UnicodeType CheckUnicodeType(LPVOID pBuffer, int cb);
108 private:
110 * Checks the line endings in a text buffer
111 * \param pBuffer pointer to the buffer containing text
112 * \param cd size of the text buffer in bytes
114 EOL CheckLineEndings(LPVOID pBuffer, int cb);
116 void SetErrorString();
118 void StripAsciiWhiteSpace(CStringA& sLine);
120 void StripWhiteSpace(CString& sLine,DWORD dwIgnoreWhitespaces, bool blame);
121 void StripAsciiWhiteSpace(CStringA& sLine,DWORD dwIgnoreWhitespaces, bool blame);
124 private:
125 std::vector<EOL> m_endings;
126 CString m_sErrorString;
127 CFileTextLines::UnicodeType m_UnicodeType;
128 EOL m_LineEndings;
129 bool m_bReturnAtEnd;