【问题标题】:How to write regular expression in UE to implement this requirement?如何在 UE 中编写正则表达式来实现这个需求?
【发布时间】:2013-07-15 18:19:46
【问题描述】:

现在我有一个由大约 1400k 行代码组成的大型 C++ 项目。现在我有一个要求:向每个派生自 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;

};

【问题讨论】:

  • 你在什么操作系统上,Windows?
  • 是的,我使用的是 Windows 7
  • 那就开始学习正则表达式吧。这一点都不难。您可以begin here 或here。

标签: regex ultraedit


【解决方案1】:

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

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

替换为

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

【讨论】:

  • 非常感谢,但我收到了警告信息:您输入的表达式无效。
  • 您确实检查了“Perl 正则表达式”选项?
  • 是的,我确实检查了“Perl regex”选项,我的 UE 版本是:UltraEdit Professional Text/HEX Editor Version 18.10.0.1016。我错过了什么吗?
  • 我刚刚在我的版本(不过是 19.00)中尝试过它,它在那里运行良好...确定没有复制/粘贴错误?
  • 啊哈,它现在工作正常,我会接受你的回答。你的正则表达式太专业了!超人!
【解决方案2】:

perl -ibak -pe "s/protected:\n/protected:\n virtual ULONG GetGestureStatus(CPoint ptTouch) { return 0;}/" file_name

【讨论】:

  • 请记住,每次protected: 出现在文件中时,它都会添加一行
  • 一个很好的答案,其实如果我能同时接受两个我也想接受你的答案。我赞成你的回答和评论。
  • 谢谢。你只能接受一个答案——游戏规则:)
猜你喜欢
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多