Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / AutoTextTestDlg.cpp
blob0b2a30e877f54457b099e982693b9c74c23bc2c4
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2020 - TortoiseGit
4 // Copyright (C) 2009, 2011, 2013-2014, 2021 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "AutoTextTestDlg.h"
23 #include "HighResClock.h"
24 #include "AppUtils.h"
25 #include <regex>
26 #include <string>
28 // CAutoTextTestDlg dialog
30 IMPLEMENT_DYNAMIC(CAutoTextTestDlg, CStandAloneDialog)
32 CAutoTextTestDlg::CAutoTextTestDlg(CWnd* pParent /*=nullptr*/)
33 : CStandAloneDialog(CAutoTextTestDlg::IDD, pParent)
37 CAutoTextTestDlg::~CAutoTextTestDlg()
41 void CAutoTextTestDlg::DoDataExchange(CDataExchange* pDX)
43 CStandAloneDialog::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);
50 BEGIN_MESSAGE_MAP(CAutoTextTestDlg, CStandAloneDialog)
51 ON_BN_CLICKED(IDC_AUTOTEXTSCAN, &CAutoTextTestDlg::OnBnClickedAutotextscan)
52 END_MESSAGE_MAP()
55 BOOL CAutoTextTestDlg::OnInitDialog()
57 CStandAloneDialog::OnInitDialog();
58 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
60 m_cContent.LimitText(200*1024);
62 return TRUE;
65 void CAutoTextTestDlg::OnBnClickedAutotextscan()
67 UpdateData();
69 m_sResult.Empty();
70 m_sTimingLabel.Empty();
71 m_cContent.GetTextRange(0, m_cContent.GetTextLength(), m_sContent);
72 if ((!m_sContent.IsEmpty())&&(!m_sRegex.IsEmpty()))
74 try
76 std::set<CString> autolist;
77 std::wstring s = static_cast<LPCWSTR>(m_sContent);
78 CHighResClock timer;
80 std::wregex regCheck;
81 regCheck = std::wregex(m_sRegex, std::regex_constants::icase | std::regex_constants::ECMAScript);
82 const std::wsregex_iterator end;
83 for (std::wsregex_iterator it(s.cbegin(), s.cend(), regCheck); it != end; ++it)
85 const std::wsmatch match = *it;
86 for (size_t i=1; i<match.size(); ++i)
88 if (match[i].second-match[i].first)
90 ATLTRACE(L"matched keyword : %s\n", std::wstring(match[i]).c_str());
91 std::wstring result = std::wstring(match[i]);
92 if (!result.empty())
94 autolist.insert(result.c_str());
99 timer.Stop();
100 for (const auto& append : autolist)
102 m_sResult += append;
103 m_sResult += L"\r\n";
105 m_sTimingLabel.Format(L"Parse time: %ld uSecs", timer.GetMusecsTaken());
107 catch (std::exception &ex)
109 m_sResult = L"Regex is invalid!\r\n" + CString(ex.what());
112 UpdateData(FALSE);