Keep case
I was thinking of two things that I'd like to request.
First: (This might be a little tough)
While setting the substitutions, I have to write the different case styles
manually for each word, Example:
To replace 'johnny brown' with 'jack garner' while keeping the proper case
style we'd have to insert the following with "match case" selected:
johnny brown (lower case) -> jack garner
JOHNNY BROWN (ALL CAPS) -> JACK GARNER
Johnny Brown (Title Case) -> Jack Garner
Johnny brown (Sentence case) -> Jack garner
You already have the "match case" checkbox which helps match the substitution
to the proper casing... but then we have to put in the substitutions manually
as many times as the number of cases in order to keep the proper casing (as
shown above).
Can you add another "keep case" checkbox so that we only have to write the term
(in any case form) and the program automatically converts it to the source
case? Example:
johnny brown (input) -> search found: Johnny brown -> Sentence case detected ->
converted 'jack garner' to 'Jack garner' (Sentence case) -> replaced
Ah! Please note: You might have to make it radio button instead of checkbox,
since match case and keep case would work against each other. Or something like
that. These two can't be active together.
(Also: You might want to check out "Métamorphose file -n- folder renamer",
they have a similar system implemented that allows them to rename whole file
names as well as specific portions of the names using basic search and reg-ex
search with user specified case types. Maybe they might help you out, or the
experience with their renamer could inspire you in some way.
http://en.wikipedia.org/wiki/Metamorphose_%28renamer%29)
If you can manage this then FoxReplace would get a big level up in terms of
replacement.
Second: (This one should be easier)
Can you make it so that the "filters" in the Fox replace options can be
separately "enabled" or "disabled"?
That way if we want we could disable filters we don't want to be active but at
the same time don't want to delete as well (it takes a lot of time to re-input
the filters y'know).
Finally. Thanks for the awesome program. I really use it a lot and it really
helps me manage a lot of tedious stuff.
Original issue reported on code.google.com by [email protected] on 21 Aug 2012 at 11:27
Hi, thank you for your suggestions. The second one is already suggested in
issue 33 as I understand it, so I changed the title to reflect the first
request only. As you say, it seams hard at first glance, but I will look at how
Métamorphose does it.
Original comment by [email protected] on 21 Aug 2012 at 3:04
- Changed title: Keep case
- Changed state: Accepted
- Added labels: Component-Logic, Component-Persistence, Component-UI, OpSys-All, Type-Enhancement
- Removed labels: Type-Defect
A note of importance. Metamorphose has two versions:
The stable version 1.
And the beta stage under development version 2.
Version 1 has the change case feature for sure as far as I know, I haven't used
the beta v2.
Original comment by [email protected] on 22 Aug 2012 at 6:29
As for the second. To be more precise:
I meant enable/disable feature (checkbox?) for the filter "groups" that are
showed in the options window. Not after opening a group and clicking on the
substitutions tab.
Though enable/disable for both would be even better.
Original comment by [email protected] on 22 Aug 2012 at 6:36
V2 has "change case" too, but I don't see "keep case", i.e. detection of
current case and applying it to the output.
And for the second one, that's what I understood ;)
Original comment by [email protected] on 22 Aug 2012 at 10:59
Yes that is true. It doesn't have the system of "detecting" the case but it
does have the system of "changing" the case. You can use that to change the
substitution term's case. All you have to do is detect the type of case.
Perhaps by using regex or something. Sorry but the detecting thing is a little
troublesome for me too. Or... wait a minute... THAT'S IT. EUREKA!!!!
I have an idea. Look... in order to replace the term in the current system I
have to write the rules a multiple number of times with minor variations as
shown above, right? So how about using the "change" function on the SEARCH term
as well as the REPLACE term and searching and replacing via that method?
For example:
The user places a rule for searching for 'johnny brown' and replacing with
'jack garner' and checks the 'keep case'.
The system converts both terms to each case seaperately and goes through the
whole page searching for thevterm with the matching case and replaces them with
the converted replacement term.
ie:
search term = johnny brown
replacement term = jack garner
'keep case' selected
Convert both to lower case, just to be sure, and run search and replace:
johnny brown (match case) -> jack garner
Convert both to ALL CAPS, and run search and replace:
JOHNNY BROWN (match case) -> JACK GARNER
Convert both to Title Case, and run search and replace:
Johnny Brown (match case) -> Jack Garner
Convert both to Sentence case, and run search and replace:
Johnny brown (match case) -> Jack garner
In essence, the system does the work of allocating temporary search and replace
rules, derived from the user input search and replace rule. A bit tedious but
it's simple, no? Or you could figure out some way to detect via regex, but that
would be harder.
Original comment by [email protected] on 23 Aug 2012 at 4:34
Although irregular terms like JOhnnY BRowN would be a problem.
Original comment by [email protected] on 23 Aug 2012 at 4:37
Maybe those could be ignored or replaced, if it matches with the default search
and replace values. An infotip note saying 'keep case' will only change [these,
these and these] cases.
Original comment by [email protected] on 23 Aug 2012 at 5:30
You're welcome. Though my method is an extremely simple one. Perhaps later you
could improve it in some way.
Original comment by [email protected] on 24 Aug 2012 at 3:22
And when's the next official upgrade planned to occur?
Original comment by [email protected] on 6 Dec 2012 at 5:14
Still haven't started on this one, but I would like to release a new version
this month.
Original comment by [email protected] on 6 Dec 2012 at 1:20
To convert to lowercase or uppercase you can use the code explained in the link
below:
http://www.hscripts.com/tutorials/javascript/string-case-converting.php
For Title Case you can use this:
http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-java
script
For Sentence case:
http://www.javascriptsource.com/forms/sentence-case.html
Please please implement this. I really need it.
Original comment by [email protected] on 13 Mar 2013 at 6:43
Thank you for the links, I will implement it when I can.
Original comment by [email protected] on 14 Mar 2013 at 3:56
Has this been fixed yet? I can't seem to find this feature in the latest
release v0.16.1... and it's been exactly 2 years since the last comment here.
Is it fixed in the beta (if there is one)? If so, where can I find it?
Original comment by [email protected] on 14 Mar 2015 at 8:04
It's not implemented yet, sorry. There have been issues with higher priority.
Original comment by [email protected] on 14 Mar 2015 at 2:59
I could try to write up a PR for this, if you think it'd be accepted; I had already worked out [email protected]'s plan, I think I could do it. I'm currently writing all my substitutions with 3 variants (Capitalized, FULLCAPS, and generic), but I'm fairly certain it'd be almost-trivial to just put this in the code.
I think I'd also like to add a "respect word boundaries" checkbox, which would effectively prepend (?=^|[\W]) and append (?=$|[^-a-zA-Z0-9]) to the match-regex, forcing it to only match phrases with word boundaries around them (so if I have 'this dude I know' → 'this dude I know' with that checkbox enabled, these dudes I know would not become this dude I knowes).
UPDATE: Just noticed that Whole words is already a match option, though isn't compatible with using Regex at the same time afaict.
@hppavilion1 If you can do it and make the pull request I'll review it and if it's good I'll accept it.
@Woundorf ...while this isn't relevant, I'd like to note how GitHub was just telling me "Woundorf commented 20 seconds from now", which is kinda funny. (I added an extra paragraph to my previous comment and you said that in the meantime)
GitHub was just telling me "Woundorf commented 20 seconds from now", which is kinda funny.
Funny indeed.
I think I'd also like to add a "respect word boundaries" checkbox, which would effectively prepend (?=^|[\W]) and append (?=$|[^-a-zA-Z0-9]) to the match-regex, forcing it to only match phrases with word boundaries around them (so if I have 'this dude I know' → 'this dude I know' with that checkbox enabled, these dudes I know would not become this dude I knowes).
UPDATE: Just noticed that Whole words is already a match option, though isn't compatible with using Regex at the same time afaict.
Maybe I could make whole words independent of plain text and regex. What it does is create a regex with a prefix and a suffix added to the input text. It takes into account Unicode characters, not just ASCII, so if you are thinking about a modification on this you should also respect Unicode, and the same goes for capitalization.
This is the "guess case" function from WR2 (MIT license). Should do the job for non-regexp.
function mimicLetterCase(originalWord, replacement) {
if(!originalWord.length) return originalWord;
var allCaps = true, titleCase = true;
// Isolated words that begin with a capital letter shall be titlecase by default and lowercase otherwise
var _tcmatch = originalWord.search('/\s/') === -1;
if( _tcmatch ) {
titleCase = allCaps = originalWord[0].toUpperCase() == originalWord[0];
}
for(var i = 0; i < originalWord.length; ++i) {
// If this letter is lowercase
if( allCaps && originalWord[i].toUpperCase() != originalWord[i] ) {
// Then the word can't be AllCaps
allCaps = false;
if( !titleCase ) break;
}
// If what comes after a space is a lowercase letter, this isn't TitleCase
else if( originalWord[i].search(/\s/) === 0 )
{
// Skip any extra space up to the second to last character
while( ++i < originalWord.length - 2 && originalWord[i].search(/\s/) === 0 );
// If the next letter isn't an uppercase letter, this ain't no titlecase
if( i >= originalWord.length || originalWord[i].search( /[A-Z]/ ) === -1 ) titleCase = false;
if( !allCaps ) break;
}
}
var result = replacement;
// All-Caps
if( allCaps ) {
result = result.toUpperCase();
}
// TitleCase
else if( titleCase ) {
result = result.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
}
// First Uppercase
else if ( originalWord[0].toUpperCase() == originalWord[0] ) {
result = result[0].toUpperCase() + result.substring(1).toLowerCase();
}
// Lowercase
else {
result = result.toLowerCase();
}
return result;
}
Corresponding description:
Letter case
Letter case determines how a replacement will be applied. You can maintain the original case or override it.
Selecting Maintain means that Word Replacer will try to guess the original case of the replaced word(s).
For example,nimbostratus => bottomwill change"Nimbostratus"to"Bottom"and"NIMBOSTRATUS"to"BOTTOM".
There are situations in which the correct case is hard to determine (is a number lowercase or uppercase?), so don't expect it to be always right.Selecting Override means that Word Replacer will disregard the original case and copy the replacement as-is.
For example,nimbostratus => BoTtOmwill change both"Nimbostratus"to"BoTtOm"and"NIMBOSTRATUS"to"BoTtOm".Word Replacer can detect the following cases: ALL-CAPS, Title Case, First uppercase, lowercase.