No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / AutoTextTestDlg.cpp
blob44769b51b5d5cb0140a8c4baf68cebdaffc64579
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2009, 2011, 2013-2014 - 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 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "AutoTextTestDlg.h"
22 #include "HighResClock.h"
23 #include "AppUtils.h"
24 #include <regex>
25 #include <string>
27 // CAutoTextTestDlg dialog
29 IMPLEMENT_DYNAMIC(CAutoTextTestDlg, CDialog)
31 CAutoTextTestDlg::CAutoTextTestDlg(CWnd* pParent /*=NULL*/)
32 : CDialog(CAutoTextTestDlg::IDD, pParent)
37 CAutoTextTestDlg::~CAutoTextTestDlg()
41 void CAutoTextTestDlg::DoDataExchange(CDataExchange* pDX)
43 CDialog::DoDataExchange(pDX);
44 DDX_Text(pDX, IDC_AUTOTEXTREGEX, m_sRegex);
45 DDX_Text(pDX, IDC_TESTRESULT, m_sResult);
46 DDX_Text(pDX, IDC_TIMINGLABEL, m_sTimingLabel);
47 DDX_Control(pDX, IDC_AUTOTEXTCONTENT, m_cContent);
51 BEGIN_MESSAGE_MAP(CAutoTextTestDlg, CDialog)
52 ON_BN_CLICKED(IDC_AUTOTEXTSCAN, &CAutoTextTestDlg::OnBnClickedAutotextscan)
53 END_MESSAGE_MAP()
56 BOOL CAutoTextTestDlg::OnInitDialog()
58 CDialog::OnInitDialog();
59 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
61 m_cContent.LimitText(200*1024);
63 return TRUE;
66 void CAutoTextTestDlg::OnBnClickedAutotextscan()
68 UpdateData();
70 m_sResult.Empty();
71 m_sTimingLabel.Empty();
72 m_cContent.GetTextRange(0, m_cContent.GetTextLength(), m_sContent);
73 if ((!m_sContent.IsEmpty())&&(!m_sRegex.IsEmpty()))
75 try
77 std::set<CString> autolist;
78 std::wstring s = m_sContent;
79 CHighResClock timer;
81 std::tr1::wregex regCheck;
82 regCheck = std::tr1::wregex(m_sRegex, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
83 const std::tr1::wsregex_iterator end;
84 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
86 const std::tr1::wsmatch match = *it;
87 for (size_t i=1; i<match.size(); ++i)
89 if (match[i].second-match[i].first)
91 ATLTRACE(_T("matched keyword : %s\n"), std::wstring(match[i]).c_str());
92 std::wstring result = std::wstring(match[i]);
93 if (!result.empty())
95 autolist.insert(result.c_str());
100 timer.Stop();
101 for (std::set<CString>::iterator it = autolist.begin(); it != autolist.end(); ++it)
103 m_sResult += *it;
104 m_sResult += _T("\r\n");
106 m_sTimingLabel.Format(_T("Parse time: %ld uSecs"), timer.GetMusecsTaken());
108 catch (std::exception &ex)
110 m_sResult = _T("Regex is invalid!\r\n") + CString(ex.what());
113 UpdateData(FALSE);