diff --git a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java index cc100fd0c..97ddd1bb3 100644 --- a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java @@ -37,27 +37,32 @@ public class CharSequenceUtils { return cs == null ? 0 : cs.length(); } - /** - *
Reverses a CharSequence as per {@link StringBuilder#reverse()}.
- * - *A null
CharSequence returns null
.
- * CharSequenceUtils.reverse(null) = null - * CharSequenceUtils.reverse("").toString() = "" - * CharSequenceUtils.reverse("bat").toString() = "tab" - *- * - * @param str the String to reverse, may be null - * @return the reversed String,
null
if null String input
- */
- public static CharSequence reverse(CharSequence str) {
- if (str == null) {
- return null;
- }
- return new StringBuilder(str).reverse();
- }
-
+ /**
+ * + * Reverses a CharSequence as per {@link StringBuilder#reverse()}. + *
+ * + *
+ * A null
CharSequence returns null
.
+ *
+ * CharSequenceUtils.reverse(null) = null + * CharSequenceUtils.reverse("").toString() = "" + * CharSequenceUtils.reverse("bat").toString() = "tab" + *+ * + * @param str + * the String to reverse, may be null + * @return the reversed String,
null
if null String input
+ */
+ public static CharSequence reverse(CharSequence str) {
+ if (str == null) {
+ return null;
+ }
+ return new StringBuilder(str).reverse();
+ }
+
/**
* Returns a new CharSequence
that is a subsequence of this
* sequence starting with the char
value at the specified
@@ -78,4 +83,39 @@ public class CharSequenceUtils {
public static CharSequence subSequence(CharSequence cs, int start) {
return cs == null ? null : cs.subSequence(start, cs.length());
}
+
+ public static int indexOf(CharSequence cs, int ch, int startPos) {
+ int max = cs.length();
+
+ if (startPos < 0) {
+ startPos = 0;
+ } else if (startPos >= max) {
+ return StringUtils.INDEX_NOT_FOUND;
+ }
+
+ if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
+ for (int i = startPos; i < max; i++) {
+ if (cs.charAt(i) == ch) {
+ return i;
+ }
+ }
+ return StringUtils.INDEX_NOT_FOUND;
+ }
+
+ // supp chars
+ if (ch <= Character.MAX_CODE_POINT) {
+ char[] surrogates = Character.toChars(ch);
+ for (int i = startPos; i < max; i++) {
+ if (cs.charAt(i) == surrogates[0]) {
+ if (i + 1 == max) {
+ break;
+ }
+ if (cs.charAt(i + 1) == surrogates[1]) {
+ return i;
+ }
+ }
+ }
+ }
+ return StringUtils.INDEX_NOT_FOUND;
+ }
}
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 4aac02d17..1dc153660 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -5390,7 +5390,7 @@ public class StringUtils {
* if the input is empty ("") or null
, may be null
* @return the passed in CharSequence, or the default
*/
- public static CharSequence defaultIfEmpty(CharSequence str, CharSequence defaultStr) {
+ public static