Redundant methods in StringUtil duplicating String functionality

Hi,

 

What is the purpose of the methods like `StringUtil.replaceChar(String,char,char)`, `StringUtil.replace(String,String,String)` and `StringUtil.indexOf(String,char)` ?

They don't seem to be doing anything substantially different from the matching methods in `String`.

And I suppose the `String` methods are more efficient and less confusing (at first I thought `StringUtil` provides null-safe variants, but apparently it doesn't).

However, `StringUtil.replace(String,String,String)` for example is used in about 200 places all over the project. Why?

 

Should I create a PR to replace the usages with the corresponding `String` methods and deprecate the redundant methods in `StringUtil`?

0
5 comments
Avatar
Permanently deleted user

Historical reasons mainly.

As to your suggestions:

`StringUtil.replaceChar(String,char,char)` with String.replace(char, char) : Yeah, totally.

`StringUtil.replace(String,String,String)` with String.replace(CharSequence, CharSequence): I don't know about that because the former doesn't create intermediate objects on non-match. (But it rewritten in JDK9 to be roughly like our implementation)

`StringUtil.indexOf(String,char)`: there is no such method in StringUtil.

0

You are right, I didn't notice that the 1st argument for `indexOf()` is a `CharSequence`.

But nevertheless it is often used for `String` values. I believe those usages could be replaced with `String.indexOf()`.

 

And good point regarding the extra instance in `replace(CharSequence,CharSequence)`.

0
Avatar
Permanently deleted user

> But nevertheless it is often used for `String` values. I believe those usages could be replaced with `String.indexOf()`.

 

Yes, totally

0
Avatar
Permanently deleted user

pushed (except com.intellij.openapi.util.text.StringUtil#charsEqualIgnoreCase ) 

0

Please sign in to leave a comment.