Skip to content

Commit bdb1ef0

Browse files
committed
Deprecate char-overloads
1 parent 13fcee1 commit bdb1ef0

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

core/src/main/java/com/google/mu/util/Substring.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ public static Pattern prefix(String prefix) {
133133

134134
/** Returns a {@code Pattern} that matches strings starting with {@code prefix}. */
135135
public static Pattern prefix(char prefix) {
136-
return new Pattern() {
137-
@Override Match match(String input) {
138-
return input.length() > 0 && input.charAt(0) == prefix ? new Match(input, 0, 1) : null;
139-
}
140-
};
136+
return prefix(Character.toString(prefix));
141137
}
142138

143139
/** Returns a {@code Pattern} that matches strings ending with {@code suffix}. */
@@ -154,13 +150,7 @@ public static Pattern suffix(String suffix) {
154150

155151
/** Returns a {@code Pattern} that matches strings ending with {@code suffix}. */
156152
public static Pattern suffix(char suffix) {
157-
return new Pattern() {
158-
@Override Match match(String input) {
159-
return input.length() > 0 && input.charAt(input.length() - 1) == suffix
160-
? new Match(input, input.length() - 1, input.length())
161-
: null;
162-
}
163-
};
153+
return suffix(Character.toString(suffix));
164154
}
165155

166156
/** Returns a {@code Pattern} that matches the first occurrence of {@code c}. */
@@ -388,13 +378,10 @@ public final String removeFrom(String string) {
388378
return match == null ? string : match.remove();
389379
}
390380

391-
/**
392-
* Returns a new string with the substring matched by {@code this} replaced by {@code
393-
* replacement}. Returns {@code string} as-is if a substring is not found.
394-
*/
381+
/** @deprecated Use {@link #replaceFrom(String, CharSequence)} instead. */
382+
@Deprecated
395383
public final String replaceFrom(String string, char replacement) {
396-
Match match = match(string);
397-
return match == null ? string : match.replaceWith(replacement);
384+
return replaceFrom(string, Character.toString(replacement));
398385
}
399386

400387
/**
@@ -574,12 +561,10 @@ public String remove() {
574561
}
575562
}
576563

577-
/**
578-
* Returns a copy of the original string with the matching substring replaced with
579-
* {@code replacement}.
580-
*/
564+
/** @deprecated Use {@link #replaceWith(CharSequence)} instead. */
565+
@Deprecated
581566
public String replaceWith(char replacement) {
582-
return getBefore() + replacement + getAfter();
567+
return replaceWith(Character.toString(replacement));
583568
}
584569

585570
/**

0 commit comments

Comments
 (0)