现在我有一个由大约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;
};
发布于 2013-07-17 17:22:43
假设您想将该行放在打开的{
之后,尝试搜索(打开Perl regexes ):
^(class\b.*\bC(?:Dialog|Wnd|ListCtrl).*\r?\n\{\r?\n)
并替换为
\1virtual ULONG GetGestureStatus(CPoint ptTouch) { return 0;}\r\n
发布于 2013-07-17 17:39:53
perl -ibak -pe "s/protected:\n/protected:\n virtual ULONG GetGestureStatus(CPoint ptTouch) { return 0;}/" file_name
https://stackoverflow.com/questions/17695682
复制相似问题