Don't import ogdf namespace
[TortoiseGit.git] / src / TortoiseProc / AutoTextTestDlg.cpp
blob1fa2a61596252fdaa15f623b5e0bb1162cac55e8
1 // TortoiseGit - 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 /*=nullptr*/)
32 : CDialog(CAutoTextTestDlg::IDD, pParent)
36 CAutoTextTestDlg::~CAutoTextTestDlg()
40 void CAutoTextTestDlg::DoDataExchange(CDataExchange* pDX)
42 CDialog::DoDataExchange(pDX);
43 DDX_Text(pDX, IDC_AUTOTEXTREGEX, m_sRegex);
44 DDX_Text(pDX, IDC_TESTRESULT, m_sResult);
45 DDX_Text(pDX, IDC_TIMINGLABEL, m_sTimingLabel);
46 DDX_Control(pDX, IDC_AUTOTEXTCONTENT, m_cContent);
49 BEGIN_MESSAGE_MAP(CAutoTextTestDlg, CDialog)
50 ON_BN_CLICKED(IDC_AUTOTEXTSCAN, &CAutoTextTestDlg::OnBnClickedAutotextscan)
51 END_MESSAGE_MAP()
54 BOOL CAutoTextTestDlg::OnInitDialog()
56 CDialog::OnInitDialog();
57 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
59 m_cContent.LimitText(200*1024);
61 return TRUE;
64 void CAutoTextTestDlg::OnBnClickedAutotextscan()
66 UpdateData();
68 m_sResult.Empty();
69 m_sTimingLabel.Empty();
70 m_cContent.GetTextRange(0, m_cContent.GetTextLength(), m_sContent);
71 if ((!m_sContent.IsEmpty())&&(!m_sRegex.IsEmpty()))
73 try
75 std::set<CString> autolist;
76 std::wstring s = m_sContent;
77 CHighResClock timer;
79 std::wregex regCheck;
80 regCheck = std::wregex(m_sRegex, std::regex_constants::icase | std::regex_constants::ECMAScript);
81 const std::wsregex_iterator end;
82 for (std::wsregex_iterator it(s.cbegin(), s.cend(), regCheck); it != end; ++it)
84 const std::wsmatch match = *it;
85 for (size_t i=1; i<match.size(); ++i)
87 if (match[i].second-match[i].first)
89 ATLTRACE(L"matched keyword : %s\n", std::wstring(match[i]).c_str());
90 std::wstring result = std::wstring(match[i]);
91 if (!result.empty())
93 autolist.insert(result.c_str());
98 timer.Stop();
99 for (const auto& append : autolist)
101 m_sResult += append;
102 m_sResult += L"\r\n";
104 m_sTimingLabel.Format(L"Parse time: %ld uSecs", timer.GetMusecsTaken());
106 catch (std::exception &ex)
108 m_sResult = L"Regex is invalid!\r\n" + CString(ex.what());
111 UpdateData(FALSE);