|
|
@@ -19,6 +19,7 @@ import java.util.NoSuchElementException;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
import net.ranides.assira.collection.query.CQuery;
|
|
|
@@ -775,6 +776,38 @@ public class StringUtils {
|
|
|
return buf.toString();
|
|
|
}
|
|
|
|
|
|
+ public static String replace(String text, int begin, int end, String newval) {
|
|
|
+ if(begin == 0) {
|
|
|
+ if(end == text.length()) {
|
|
|
+ return newval;
|
|
|
+ }
|
|
|
+ return newval + text.substring(end);
|
|
|
+ }
|
|
|
+ if(end == text.length()) {
|
|
|
+ if(begin == 0) {
|
|
|
+ return newval;
|
|
|
+ }
|
|
|
+ return text.substring(0, begin) + newval;
|
|
|
+ }
|
|
|
+ return text.substring(0, begin) + newval + text.substring(end);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static CharSequence replace(CharSequence text, int begin, int end, CharSequence newval) {
|
|
|
+ if(begin == 0) {
|
|
|
+ if(end == text.length()) {
|
|
|
+ return newval;
|
|
|
+ }
|
|
|
+ return concat(newval, text.subSequence(end, text.length()));
|
|
|
+ }
|
|
|
+ if(end == text.length()) {
|
|
|
+ if(begin == 0) {
|
|
|
+ return newval;
|
|
|
+ }
|
|
|
+ return concat(text.subSequence(0, begin), newval);
|
|
|
+ }
|
|
|
+ return concat(text.subSequence(0, begin), newval, text.subSequence(end, text.length()));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Concatenates all values using "separator".
|
|
|
* Values are first converted to text using "toString" method.
|
|
|
@@ -1344,6 +1377,10 @@ public class StringUtils {
|
|
|
return new NCSequence(n, chr);
|
|
|
}
|
|
|
|
|
|
+ public static CharSequence concat(CharSequence... fragments) {
|
|
|
+ return new ConcatSequence(fragments);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns length of the string, or zero if string is null.
|
|
|
*
|
|
|
@@ -1789,5 +1826,43 @@ public class StringUtils {
|
|
|
return text.subSequence(begin,end).toString();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private static final class ConcatSequence implements CharSequence {
|
|
|
+ private final CharSequence[] fragments;
|
|
|
+
|
|
|
+ public ConcatSequence(CharSequence[] fragments) {
|
|
|
+ this.fragments = fragments;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int length() {
|
|
|
+ int out = 0;
|
|
|
+ for(CharSequence s : fragments) {
|
|
|
+ out += s.length();
|
|
|
+ }
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public char charAt(int index) {
|
|
|
+ for(CharSequence s : fragments) {
|
|
|
+ if(index < s.length()) {
|
|
|
+ return s.charAt(index);
|
|
|
+ }
|
|
|
+ index -= s.length();
|
|
|
+ }
|
|
|
+ throw new StringIndexOutOfBoundsException(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CharSequence subSequence(int start, int end) {
|
|
|
+ return new CSSub(this, start, end);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return StringUtils.join(fragments, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|