Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Multiline Search & Replace
rickg22:
Hi guys! I'm modifying my fresh SVN copy of Code::Blocks to support Multi-line search and replace (I'm needing it to refactor a 400-files ASP project, and we need to save as much time as possible).
Currently I've only been able to modify the replace dialog (the search dialog is not as critical), and only the XRC (but I'm about to start with the C++ code). See the attachment for a screenshot.
What do you think?
[attachment deleted by admin]
rickg22:
I've managed to make the changes in replacedlg.cpp.
In some files, replacing works, but in others, it doesn't. I've realized it's a line-endings issue. The wxTextCtrl interprets a line feed as LF, while the files can vary their endings in LF, CR or CRLF.
To solve this, I need to make the following steps:
If the search string does NOT contains a CR or LF, search normally.
If it does,
1) Get the EOL mode from C::B.
2) Convert the "find" string to this EOL mode.
3) Convert the file to be searched (the in-memory buffer, i mean) to this EOL mode so line endings are consistent. We're going to replace in files, anyway.
4) Convert the "replace" string to this EOL mode.
5) Find and replace the string as we'd do with any other strings.
This should be done in EditorManager::Replace(cbStyledTextCtrl* control, cbFindReplaceData* data).
I'll keep posting my progress.
BTW, regex search hasn't been tested yet. Wish me luck! :)
blueshake:
Seems cool,waiting for your good news. :D
rickg22:
Progress update.
Sun, Nov 8, 2009.
The Multi-line Search and replace algorithm has been finished and tested successfully, in an unsaved file, with default EOL mode set to CRLF.
The EOL conversion of the search and replace expressions is done inside replacedlg.cpp. Inside EditorManager::Replace and EditorManager::ReplaceInFiles we check the search expression for LFs and CRs. If there's a match, the whole file is converted to the current EOL mode to avoid false positives/negatives. Then the search takes place normally.
Search & Replace in a single file works, for both normal and regex searches.
Extended Regular Expressions is enabled.
Before:
--- Code: ---<html>
<body>
hola mundo!
</body>
</html>
--- End code ---
Search Expression:
--- Code: ---<html>
<body>
(.*)
</body>
</html>
--- End code ---
Replace expression:
--- Code: ---<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello world!</title>
</head>
<body>
\1
</body>
</html>
--- End code ---
After:
--- Code: ---<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello world!</title>
</head>
<body>
hola mundo!
</body>
</html>
--- End code ---
There are still some quirks in the UI that need to be worked on.
Multi-line S&R in files has not been tested yet.
Will continue to report tomorrow.
Good night!
mariocup:
seems very very cool.
Navigation
[0] Message Index
[#] Next page
Go to full version