PowerToys/src/modules/powerrename/lib/PowerRenameRegEx.h

67 lines
1.9 KiB
C
Raw Normal View History

#pragma once
#include "pch.h"
#include <vector>
#include <string>
#include "srwlock.h"
#include "PowerRenameInterfaces.h"
#define DEFAULT_FLAGS MatchAllOccurences
class CPowerRenameRegEx : public IPowerRenameRegEx
{
public:
// IUnknown
IFACEMETHODIMP QueryInterface(_In_ REFIID iid, _Outptr_ void** resultInterface);
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();
// IPowerRenameRegEx
IFACEMETHODIMP Advise(_In_ IPowerRenameRegExEvents* regExEvents, _Out_ DWORD* cookie);
IFACEMETHODIMP UnAdvise(_In_ DWORD cookie);
IFACEMETHODIMP GetSearchTerm(_Outptr_ PWSTR* searchTerm);
IFACEMETHODIMP PutSearchTerm(_In_ PCWSTR searchTerm, bool forceRenaming);
IFACEMETHODIMP GetReplaceTerm(_Outptr_ PWSTR* replaceTerm);
IFACEMETHODIMP PutReplaceTerm(_In_ PCWSTR replaceTerm, bool forceRenaming);
IFACEMETHODIMP GetFlags(_Out_ DWORD* flags);
IFACEMETHODIMP PutFlags(_In_ DWORD flags);
IFACEMETHODIMP PutFileTime(_In_ SYSTEMTIME fileTime);
IFACEMETHODIMP ResetFileTime();
IFACEMETHODIMP Replace(_In_ PCWSTR source, _Outptr_ PWSTR* result);
static HRESULT s_CreateInstance(_Outptr_ IPowerRenameRegEx **renameRegEx);
protected:
CPowerRenameRegEx();
virtual ~CPowerRenameRegEx();
void _OnSearchTermChanged();
void _OnReplaceTermChanged();
void _OnFlagsChanged();
void _OnFileTimeChanged();
size_t _Find(std::wstring data, std::wstring toSearch, bool caseInsensitive, size_t pos);
PowerRename: Add Lookbehind (#7571) * Add boost-regex library * If enabled use boost lib for regex Add property `_useBoostLib` to `CPowerRenameRegEx`. If enabled for replacements with regular expressions the Boost Library is used instead of the Standard Library. * Extend signatures to create RegEx with Boost Extend create and constructor singatures of `CPowerRenameRegEx` with an option to enable (or disabled, which is default) the Boost Library. * Verify Lookbehind fails with STD library To verify that the boost library is disabled as expected, check if a lookbehind fails. * Add Unit tests for RegEx with Boost Add unit tests to verify regex replacement with Boost Library. They are copied and adapted from the Standard Library tests. * Improve verify capturing groups test with Boost It is possible to use a capturing group followed by numbers as replacement if the group number is enclosed in curly braces. Added test cases based on the Standard Library tests. * Add useBoostLib to settings interface * Get library option from settings object * Reduce signatures of RegEx by "useBoost" Remove the parameter added in 19105cf, as it became obsolete. * Settings: Read useBoostLib from JSON file * Add UseBoostLib Option to UI * Boost Lib label states the regex syntax difference * Fix Regex with Boost Lib tests - Do not load settings another time in CPowerRenameRegEx ctor - Set flag correctly in standard library regex tests * Add "lookbehind" to dictionary * change Library to lowercase, and also add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * Change Library to lowercase and add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2020-11-09 19:13:43 +01:00
bool _useBoostLib = false;
DWORD m_flags = DEFAULT_FLAGS;
PWSTR m_searchTerm = nullptr;
PWSTR m_replaceTerm = nullptr;
SYSTEMTIME m_fileTime = {0};
bool m_useFileTime = false;
CSRWLock m_lock;
CSRWLock m_lockEvents;
DWORD m_cookie = 0;
struct RENAME_REGEX_EVENT
{
IPowerRenameRegExEvents* pEvents;
DWORD cookie;
};
_Guarded_by_(m_lockEvents) std::vector<RENAME_REGEX_EVENT> m_renameRegExEvents;
long m_refCount = 0;
};