|
@@ -100,12 +100,12 @@ public final class Strings {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static boolean contains(String text, char value) {
|
|
|
|
|
- return text!=null && text.indexOf(value) != -1;
|
|
|
|
|
|
|
+ public static boolean contains(CharSequence text, char value) {
|
|
|
|
|
+ return -1 != indexOf(text, value, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static boolean contains(String text, CharSequence value) {
|
|
|
|
|
- return text!=null && text.contains(value);
|
|
|
|
|
|
|
+ public static boolean contains(CharSequence text, CharSequence value) {
|
|
|
|
|
+ return -1 != indexOf(text, value, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static int length(String value) {
|
|
public static int length(String value) {
|
|
@@ -126,6 +126,65 @@ public final class Strings {
|
|
|
return new ArrayWrapper(data);
|
|
return new ArrayWrapper(data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static int indexOf(CharSequence text, char value, int offset) {
|
|
|
|
|
+ if(null == text) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ for(int i=0,n=text.length(); i<n; i++) {
|
|
|
|
|
+ if(value == text.charAt(i)) {
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings({"PMD", "empty-statement"})
|
|
|
|
|
+ public static int indexOf(CharSequence text, CharSequence value, int offset) {
|
|
|
|
|
+ // implementation copied from java.lang.String
|
|
|
|
|
+ // we don't want to change tricky details
|
|
|
|
|
+
|
|
|
|
|
+ if(null == text || null == value) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int sourceCount = text.length();
|
|
|
|
|
+ int targetCount = value.length();
|
|
|
|
|
+
|
|
|
|
|
+ if (offset >= sourceCount) {
|
|
|
|
|
+ return (targetCount == 0 ? sourceCount : -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (offset < 0) {
|
|
|
|
|
+ offset = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (targetCount == 0) {
|
|
|
|
|
+ return offset;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ char first = value.charAt(0);
|
|
|
|
|
+ int max = (sourceCount - targetCount);
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = offset; i <= max; i++) {
|
|
|
|
|
+ /* Look for first character. */
|
|
|
|
|
+ if (text.charAt(i) != first) {
|
|
|
|
|
+ while (++i <= max && text.charAt(i) != first);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* Found first character, now look at the rest of v2 */
|
|
|
|
|
+ if (i <= max) {
|
|
|
|
|
+ int j = i + 1;
|
|
|
|
|
+ int end = j + targetCount - 1;
|
|
|
|
|
+ for (int k = 1; j < end && text.charAt(j)
|
|
|
|
|
+ == value.charAt(k); j++, k++);
|
|
|
|
|
+
|
|
|
|
|
+ if (j == end) {
|
|
|
|
|
+ /* Found whole string. */
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Cholernie przekombinowana metoda, która dodaje do javy pseudo-support dla
|
|
* Cholernie przekombinowana metoda, która dodaje do javy pseudo-support dla
|
|
|
* psuedo-raw-string-literals. Używa się jej prosto: <code>Strings.raw(/*raw text here;*/)</code>
|
|
* psuedo-raw-string-literals. Używa się jej prosto: <code>Strings.raw(/*raw text here;*/)</code>
|