regex - UE中如何编写正则表达式来实现这个需求呢?

标签 regex ultraedit

现在我有一个大型 C++ 项目,由大约 1400k 行代码组成。现在我有一个要求:向从CDialog、CWnd或CListCtrl派生的每个类添加一行代码。我手动完成此操作是不可能的。我想也许UltraEdit正则表达式可以帮我一把,但我自己不会写相关的正则表达式。

有人可以帮助我吗?

这是要添加的代码行:

virtual ULONG GetGestureStatus(CPoint ptTouch) { return 0;}

这是我的代码结构(仅供引用):

class CRibbonAddPlaceDialog : public CDialog
{
    DECLARE_DYNAMIC(CRibbonAddPlaceDialog)

public:
    CRibbonAddPlaceDialog();
    virtual ~CRibbonAddPlaceDialog();
    enum { IDD = IDD_RIBBON_ADDPLACE };

protected:
    virtual ULONG GetGestureStatus(CPoint ptTouch) { return 0;}//the line to add
    virtual void DoDataExchange(CDataExchange* pDX);
    DECLARE_MESSAGE_MAP()
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnDestroy();
    virtual BOOL OnInitDialog();
    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
public:
    BOOL AddButton(CFX_WideString csTitle, AddPlaceButtonProc proc, void* pClientData, CFX_DIBitmap* pButtonImage);
public:

    CReader_RibbonFilePageManager* m_pRibbonFilePageMgr;
    CReader_RibbonStyle_Static*       m_pAddPlace;
    CReader_RibbonStyle_Static*       m_pAddPlaceTip;
    CTypedPtrArray<CPtrArray, buttondata*> m_arButtonData;
    CTypedPtrArray<CPtrArray, CBCGPButton*>m_arButton;

};

最佳答案

假设您想将该行放在开头 { 之后,请尝试搜索(打开 Perl 正则表达式):

^(class\b.*\bC(?:Dialog|Wnd|ListCtrl).*\r?\n\{\r?\n)

并替换为

\1virtual ULONG GetGestureStatus(CPoint ptTouch) { return 0;}\r\n

关于regex - UE中如何编写正则表达式来实现这个需求呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17695682/

相关文章:

vb.net 中字符串的正则表达式匹配

html - 如何在 UltraEdit 中将 CSS 链接到 HTML?

regex - UltraEdit(或 MacOS 正则表达式): Delete multiple lines in xml

javascript - 正则表达式匹配 Markdown 代码块

c# - 正则表达式中的法语/葡萄牙语扩展 ASCII 符号

javascript - 为什么 RegEx.test 会在后续调用中更改结果?

regex - UltraEdit 正则表达式替换功能超出可用资源

javascript - 如何从命令行将参数传递给UltraEdit脚本?

encoding - 有没有办法在 UltraEdit 中获取文本文件的编码?

regex - 在 D 中的编译时评估正则表达式