git fetch show progress
[TortoiseGit.git] / src / TortoiseProc / AutoTextTestDlg.cpp
blob2236535d540decbe37632cd01ed0c4b87d287205
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)
33 , m_sRegex(_T(""))
34 , m_sResult(_T(""))
35 , m_sTimingLabel(_T(""))
40 CAutoTextTestDlg::~CAutoTextTestDlg()
44 void CAutoTextTestDlg::DoDataExchange(CDataExchange* pDX)
46 CDialog::DoDataExchange(pDX);
47 DDX_Text(pDX, IDC_AUTOTEXTREGEX, m_sRegex);
48 DDX_Text(pDX, IDC_TESTRESULT, m_sResult);
49 DDX_Text(pDX, IDC_TIMINGLABEL, m_sTimingLabel);
50 DDX_Control(pDX, IDC_AUTOTEXTCONTENT, m_cContent);
54 BEGIN_MESSAGE_MAP(CAutoTextTestDlg, CDialog)
55 ON_BN_CLICKED(IDC_AUTOTEXTSCAN, &CAutoTextTestDlg::OnBnClickedAutotextscan)
56 END_MESSAGE_MAP()
59 BOOL CAutoTextTestDlg::OnInitDialog()
61 CDialog::OnInitDialog();
62 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
64 m_cContent.LimitText(200*1024);
66 return TRUE;
69 void CAutoTextTestDlg::OnBnClickedAutotextscan()
71 UpdateData();
73 m_sResult.Empty();
74 m_sTimingLabel.Empty();
75 m_cContent.GetTextRange(0, m_cContent.GetTextLength(), m_sContent);
76 if ((!m_sContent.IsEmpty())&&(!m_sRegex.IsEmpty()))
78 try
80 std::set<CString> autolist;
81 std::wstring s = m_sContent;
82 CHighResClock timer;
84 std::tr1::wregex regCheck;
85 regCheck = std::tr1::wregex(m_sRegex, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
86 const std::tr1::wsregex_iterator end;
87 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
89 const std::tr1::wsmatch match = *it;
90 for (size_t i=1; i<match.size(); ++i)
92 if (match[i].second-match[i].first)
94 ATLTRACE(_T("matched keyword : %s\n"), std::wstring(match[i]).c_str());
95 std::wstring result = std::wstring(match[i]);
96 if (!result.empty())
98 autolist.insert(result.c_str());
103 timer.Stop();
104 for (std::set<CString>::iterator it = autolist.begin(); it != autolist.end(); ++it)
106 m_sResult += *it;
107 m_sResult += _T("\r\n");
109 m_sTimingLabel.Format(_T("Parse time: %ld uSecs"), timer.GetMusecsTaken());
111 catch (std::exception &ex)
113 m_sResult = _T("Regex is invalid!\r\n") + CString(ex.what());
116 UpdateData(FALSE);