Also support UTF8 content in serial patches
[TortoiseGit.git] / src / TortoiseProc / SerialPatch.cpp
blobb6d88c5cd4d7e35c32e92271899619850cb7434f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2016 - TortoiseGit
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.
20 #include "stdafx.h"
21 #include "SerialPatch.h"
22 #include "Git.h"
24 CSerialPatch::CSerialPatch()
28 CSerialPatch::~CSerialPatch()
31 int CSerialPatch::Parse(const CString& pathfile, bool parseBody)
33 m_PathFile = pathfile;
35 CFile PatchFile;
37 if (!PatchFile.Open(m_PathFile, CFile::modeRead))
38 return -1;
40 PatchFile.Read(CStrBufA(m_Body, (UINT)PatchFile.GetLength()), (UINT)PatchFile.GetLength());
41 PatchFile.Close();
43 try
45 int start = 0;
46 CStringA one;
47 one = m_Body.Tokenize("\n", start);
49 if (start == -1)
50 return -1;
51 one = m_Body.Tokenize("\n", start);
52 if (one.GetLength()>6)
53 CGit::StringAppend(&m_Author, (BYTE*)(LPCSTR)one + 6, CP_UTF8, one.GetLength() - 6);
55 if (start == -1)
56 return -1;
57 one = m_Body.Tokenize("\n", start);
58 if (one.GetLength()>6)
59 CGit::StringAppend(&m_Date, (BYTE*)(LPCSTR)one + 6, CP_UTF8, one.GetLength() - 6);
61 if (start == -1)
62 return -1;
63 one = m_Body.Tokenize("\n", start);
64 if (one.GetLength()>9)
66 CGit::StringAppend(&m_Subject, (BYTE*)(LPCSTR)one + 9, CP_UTF8, one.GetLength() - 9);
67 while (m_Body.GetLength() > start && m_Body.GetAt(start) == _T(' '))
69 one = m_Body.Tokenize("\n", start);
70 CGit::StringAppend(&m_Subject, (BYTE*)(LPCSTR)one, CP_UTF8, one.GetLength());
74 if (!parseBody)
75 return 0;
77 while (start > 0)
79 if (m_Body.Mid(start - 1, 2) == L"\n\n")
80 break;
81 m_Body.Tokenize("\n", start);
84 if (start == -1)
85 return -1;
87 if (start + 1 < m_Body.GetLength())
88 CGit::StringAppend(&m_strBody, (BYTE*)(LPCSTR)m_Body + start + 1, CP_UTF8, m_Body.GetLength() - start - 1);
90 catch (CException *)
92 return -1;
95 return 0;