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`?
请先登录再写评论。
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.
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)`.
> But nevertheless it is often used for `String` values. I believe those usages could be replaced with `String.indexOf()`.
Yes, totally
https://github.com/JetBrains/intellij-community/pull/570
pushed (except com.intellij.openapi.util.text.StringUtil#charsEqualIgnoreCase )