Farlap
Jul 18 2012, 2:42 am
By: Roy  

Jul 18 2012, 2:42 am Roy Post #1

An artist's depiction of an Extended Unit Death

Background

FARLAP
Find And Replace Like A Pro

Basically, this was a small little program I wrote for doing a Find/Replace on multiple lines. Normally, I would use Notepad++ or a similar program for a Find/Replace on things like large lists of triggers, but it would only allow me to enter one line in, and I'm not well-versed in using Regex across multiple lines. The extended Find/Replace worked alright, but there was an annoying process that I'd have to do in order to get the Find string I wanted to use.

So, if you're like me and use Find/Replace more than you probably should, this program is for you!




I likely wouldn't have made this if not for Azrael, hence the color scheme/icon.

FEATURES/UPDATES (sorted by newest):
2014-07-11
  • Keep Matches Only feature!
2013-16-06
  • Resize boxes in the window!
  • Remembers previous settings!
  • Save to a Farlap file!
  • Load from a Farlap file!
  • Save output to a text file!
  • Load input from a text file!
2012-07-28
  • Scroll bars don't always display!
  • Major optimization for large text inputs!
2012-07-18
  • Regex!
2012-07-17
  • Case Insensitive/Uninsensitive!
  • Option for manual Find/Replace (in case you're doing something very large and are experiencing performance issues)!
  • Counter for how many replaces you've made!
2012-07-16 (Private release)
  • Small file size! (51KB)
  • One file!
  • Multi-Line Find!
  • Multi-Line Replace!
  • Instant Find/Replace as you type!


This program uses .NET 4.0, so if you don't have that, it won't work. I can compile this under a lower version of .NET if you need it for whatever reason (just send me a PM or something).

Download: Farlap DLDB Link (2014-07-11)

Post has been edited 15 time(s), last time on Nov 18 2015, 2:30 am by Roy.




Jul 18 2012, 3:19 am Azrael Post #2



Oh god, this is so sexy! :thumbup:

Rest assured, every computer I own from this day forward shall have this program on it.




Jul 18 2012, 3:26 am Aristocrat Post #3



Does this take regex? Most of my find/replace tasks involve some sort of regular expression and it would be awesome if this did.



None.

Jul 18 2012, 3:39 am Roy Post #4

An artist's depiction of an Extended Unit Death

No, this just takes in string literals. If you're versed in Regex, I'm sure you can find much more powerful text programs to accomplish your task.

Though nothing's stopping me from adding a Regex option, I suppose.




Jul 18 2012, 8:11 am NudeRaider Post #5

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

What about formatted text? I don't suppose I can paste a word document and keep all the formatting or even find and replace formattings?




Jul 18 2012, 1:32 pm Roy Post #6

An artist's depiction of an Extended Unit Death

Nope. I could switch the TextBoxes to be RichTextBoxes to keep formatting, perhaps, but checking font size/family/etc might be a bit tricky for a Find/Replace function.




Jul 19 2012, 3:55 am Roy Post #7

An artist's depiction of an Extended Unit Death

Quote from NudeRaider
What about formatted text? I don't suppose I can paste a word document and keep all the formatting or even find and replace formattings?
I looked further into this and it seems like a real pain to implement. I'm gonna be lazy for now and just say it isn't and likely won't be supported.

Quote from Aristocrat
Does this take regex?
It does now!

Cool shit:

In the above example, I've decided that I want all my Bring conditions to require exactly 1 Terran Marine, without changing other things such as location and player owner.




Nov 9 2012, 11:18 pm Azrael Post #8



Just used this with regex to edit over 1000 triggers simultaneously. It wouldn't have been possible to do it otherwise, except manually. I almost feel like this should be posted in the forum for mapping tools as well :P




Nov 19 2012, 11:11 pm Oh_Man Post #9

Find Me On Discord (Brood War UMS Community & Staredit Network)

OK call me a nub but how is this any different for when I put my triggers into notepad and find/replace them that way??




Nov 20 2012, 12:29 am BiOAtK Post #10



Quote from Roy
Normally, I would use Notepad++ or a similar program for a Find/Replace on things like large lists of triggers, but it would only allow me to enter one line in, and I'm not well-versed in using Regex across multiple lines. The extended Find/Replace worked alright, but there was an annoying process that I'd have to do in order to get the Find string I wanted to use.

Quote from Oh_Man
OK call me a nub but how is this any different for when I put my triggers into notepad and find/replace them that way??




None.

Nov 20 2012, 12:37 am Roy Post #11

An artist's depiction of an Extended Unit Death

Quote from Oh_Man
OK call me a nub but how is this any different for when I put my triggers into notepad and find/replace them that way??
From regular Notepad? Why, there's a number of advantages! Off the top of my head:

1) Notepad's Find/Replace is confined to a single, short line to enter your patterns; this can be difficult if you're trying to find and replace variations of a long expression.
2) Notepad cannot Find/Replace across multiple lines; you are confined to single-line modifications, which isn't optimal for a lot of circumstances.
3) Notepad cannot use Regex patterns to find and replace. Regex, if you don't already know, is a powerful text matcher that can do much more than a basic Find/Replace.
4) Notepad cannot Find/Replace on-the-fly, and you have to undo your changes to get the original input again. Farlap preserves the input while providing the output for convenience.
5) Notepad requires operating inside a window for Find/Replace, which can be seen as a minor inconvenience as opposed to having it all laid out for you in one window. Yeah, this is more opinion-based; wanna fight about it?

If you were referring to Notepad++, this program has a significantly smaller edge over it (As Extended Character and Regex support allows Notepad++ to search across multiple lines, although it's arguably not as easy). But even here, there's a few minor advantages to Farlap's Regex, such as the ability to have patterns inside of lookaheads (which isn't available for a lot of Regex implementations). But more importantly, the convenience advantages I listed above still apply; this program makes it easier to find and replace than even Notepad++, even if they both can functionally perform most of your tasks.

That's really the point of this program: make replacing text easier. Perhaps I should add a screenshot that does a multi-line find/replace, as that's particularly one of the program's strong points.

Play around with it a little; convenience can only really be experienced first-hand.

Post has been edited 1 time(s), last time on Nov 20 2012, 12:55 am by Roy.




Nov 20 2012, 12:53 am Oh_Man Post #12

Find Me On Discord (Brood War UMS Community & Staredit Network)

I'm SOLD!!

EDIT: Ok well there is one problem I think notepad is a lot quicker at this then farlap. When I copy my 20k of trigs into notepad it takes about 5 seconds of Not Responding until the text appears.

I did this with FARLAP and... I think it died.

DOUBLE EDIT: OK it worked after about 2 minutes. But now even when I'm trying to use the find replace feature it lags for another 2 minutes whenever I try to find something. In notepad this is instantaneous.

Not sure why notepad is superior to farlap in this regard, but atm it is a deal breaker for me.

Post has been edited 2 time(s), last time on Nov 20 2012, 1:02 am by Oh_Man.




Nov 20 2012, 1:59 pm Azrael Post #13



Did you enable Manual Refresh? That prevents it from updating until you're filled in all the relevant forms.

I was editing over 500,000 lines of text recently (31k triggers) and it took less than a minute to update it.

The fact is that there are things this program does which Notepad simply cannot do, especially when dealing with triggers.




Nov 21 2012, 12:19 am Roy Post #14

An artist's depiction of an Extended Unit Death

Quote from Oh_Man
OK it worked after about 2 minutes. But now even when I'm trying to use the find replace feature it lags for another 2 minutes whenever I try to find something. In notepad this is instantaneous.
The hang is primarily caused by the UI update. I've considered having a worker thread issue batches of text to the main thread to prevent it from becoming unresponsive, but I've forgotten how the dispatcher works in WPF and would have to review one of my older projects which handled something very similar (the project in question is on my external and I've been too lazy to pull it off).

Quote from Oh_Man
Not sure why notepad is superior to farlap in this regard, but atm it is a deal breaker for me.
If the actual operation is slower in Farlap (barring the UI update), it's probably because I rolled my own find/replace algorithm (had to for getting a replace count without running through the text twice), and I didn't write it to be unchecked, so there's some overhead from the .NET Framework that Notepad does not have. I can try doing some optimizations around the framework, but what I'm using now as an algorithm is as efficient as I believe I can get it, and I don't think I'm smarter than the compiler in terms of micro-optimizations.

I remember an older version of Notepad actually had a similar problem as well.

Quote from Azrael
Did you enable Manual Refresh? That prevents it from updating until you're filled in all the relevant forms.
Maybe I should make a config file to remember your settings (or at least let you set the default). Everyone who uses this seems to be working with large amounts of text, so the automatic refresh seems to be a bad default option.




Feb 4 2013, 7:54 pm Wormer Post #15



This is a cool stuff, and I don't want to sound rude, but you can achieve this with Vim and it's regular expressions.

For instance, the following Vim substitution command:
Code
:%s /\(Bring(.\{-}, "\).\{-}\(", .\{-}, \).\{-}, \d*/\1Terran Marine\2Exactly, 1/


Does exactly this:


Vim owns Notepad++ so bad.

Post has been edited 2 time(s), last time on Feb 4 2013, 8:11 pm by Wormer.



Some.

Feb 4 2013, 8:21 pm Azrael Post #16



I just downloaded Vim to try it, and it seems horrifically unintuitive. There is nothing to indicate regex can be used, nor how to use it. Additionally, I see no method of searching for a block of text which includes multiple lines, while utilizing regex or otherwise. The "find and replace" form is just as terrible and outdated as every other text editing program I've had the misfortune of using, which makes sense since it's derived directly from Notepad of all things.

If you want to find and replace like a pro, I'd suggest using Farlap. Nothing could be more efficient.




Feb 4 2013, 8:31 pm Wormer Post #17



Vim is very efficient. But the learning curve is really hard. As a way to start I can recommend to run Vim in easy mode (so called eVim). In eVim you enter Ctrl+O and then colon to get into command mode. To get help on substitution you need to enter 'help :s' in command mode. Command 'help pattern' will give you help on Vim regexpr patterns...

I'm using Vim for several years already. I had several attempts to Vim, but now I'm starting to feel pretty comfortable with it. At this point I'm using Vim for everything: starting from simple text editing to programming and writing SC triggers.

P.S.
To search for a block of text that contains multiple lines you use \n that matches the end of line (it automatically takes into account which linebreaks the file uses: unix, win or mac).

P.P.S
Probably the best way to start learning Vim regular expressions is to read usr_27.txt (type 'help usr_27' in command mode).

Post has been edited 8 time(s), last time on Feb 4 2013, 8:49 pm by Wormer.



Some.

Feb 4 2013, 8:54 pm Azrael Post #18



Quote from Wormer
To search for a block of text that contains multiple lines you use \n that matches the end of line
Right, and you can do this in Notepad++ as well. It's still grossly inefficient compared to Farlap, which doesn't require \n or escape characters or reformatting the search terms just for finding normal blocks of text, or replacing something with a block of text.




Feb 4 2013, 8:56 pm Wormer Post #19



Quote from Azrael
Quote from Wormer
To search for a block of text that contains multiple lines you use \n that matches the end of line
Right, and you can do this in Notepad++ as well. It's still grossly inefficient compared to Farlap, which doesn't require \n or escape characters or reformatting the search terms just for finding normal blocks of text, or replacing something with a block of text.
I don't understand what do you mean while speaking about finding "normal blocks of text"? If you need to do a substitution in each line that matches a given regexpr pattern then you use ':%s /pattern/replacetext/g' in Vim. It replaces each entry of pattern with replacetext in each line.



Some.

Feb 4 2013, 9:00 pm Azrael Post #20



By "normal" blocks of text, I mean non-regex.

It also searches for blocks of regex text without the need for \n, and the same is true for replacement, there are no metacharacters or escape characters required.

For a better understanding of the inherent problems with these other, less efficient editors, check the "Background" collapse box in the first post.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
[2024-4-17. : 3:26 am]
O)FaRTy1billion[MM] -- i have to ask for minerals first tho cuz i don't have enough to send
[2024-4-17. : 1:53 am]
Vrael -- bet u'll ask for my minerals first and then just send me some lousy vespene gas instead
[2024-4-17. : 1:52 am]
Vrael -- hah do you think I was born yesterday?
[2024-4-17. : 1:08 am]
O)FaRTy1billion[MM] -- i'll trade you mineral counts
[2024-4-16. : 5:05 pm]
Vrael -- Its simple, just send all minerals to Vrael until you have 0 minerals then your account is gone
[2024-4-16. : 4:31 pm]
Zoan -- where's the option to delete my account
[2024-4-16. : 4:30 pm]
Zoan -- goodbye forever
Please log in to shout.


Members Online: Dem0n, lil-Inferno