Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding CaseSensitive parameter to StrReplace. #103

Open
wants to merge 1 commit into
base: alpha
from

Conversation

Projects
None yet
2 participants
@HelgeffegleH
Copy link
Contributor

commented Jun 15, 2018

Hello 馃憢

New:

ReplacedStr := StrReplace(Haystack, SearchText [, ReplaceText, CaseSensitive := false, OutputVarCount, Limit := -1])

Implementation is copied from BIF_InStr.

Reason for change: convenience.

Adding CaseSensitive parameter to StrReplace.
New:

ReplacedStr := StrReplace(Haystack, SearchText [, ReplaceText, CaseSensitive := false, OutputVarCount, Limit := -1])

Implementation is copied from BIF_InStr.

Reason for change: convenience.
@Lexikos

This comment has been minimized.

Copy link
Owner

commented Jun 23, 2018

This seems like it could be useful, but I wonder: how often would it be used, and how often are the OutputVarCount and Limit parameters used?

It is already possible to control the case-sensitivity of StrReplace (though perhaps not in the most convenient way), whereas OutputVarCount and Limit provide functionality that would otherwise require either a custom replacement function or RegExReplace. The current parameter order is identical to RegExReplace, which aides memorization.

I couldn't find any instance of StrReplace with more than three parameters in any of my scripts, but I know I have used OutputVarCount (or at least ErrorLevel with StringReplace). I do not recall having ever used StringCaseSense with StrReplace/StringReplace, although that might be because I am comfortable with regex. (I'm not sure that I've used StringCaseSense at all.)

@HelgeffegleH

This comment has been minimized.

Copy link
Contributor Author

commented Jun 23, 2018

Hello.

I wonder: how often would it be used

In one sense it will always be used, that is, since not specifying the parameter is equivalent to passing false. I think it is very common that people do not set stringcasesense 'off', even when this is the desired setting, just because this is default unless changed in auto-exec. section, that is a mistake for a general/shared function. Further, I would probably often specify true to avoid using the (much slower) locale obeying function when replacing something like ',' with '|', where neither locale nor case matters. That would probably be a rarely significant optimisation though.

I do not recall having ever used StringCaseSense with StrReplace/StringReplace

I think stringcasesense is rarely used with strreplace, because, either the code author doesn't realise that the replacement will be case sensitive if used in a script where stringcasesense is 'on', that is, it is happy with the default stringcasesense 'off', or the author is aware and then uses regexreplace with or without the i option, since it is more succinct than setting and restoring stringcasesense. Personally, I use regexreplace sometimes just because of this, and sometimes I forget or just do not care about the implications of stringcasesense and use strreplace. Some of my code most certainly will not work well if put in a script where stringcasesense 'on' has been set in the auto-exec. section.

Regarding the parameter order, I'm quite neutral to it. I made a guess that the new parameter would be specified more often than the others. Whenever I use the OutputVarCount or Limit parameters for either regexreplace or strreplace, I need to check the docs for the order anyways.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.