@@ -1075,10 +1075,11 @@ static int countUnescaped(String haystack, char needle, int start, int end) {
10751075 */
10761076 private static int nextQuote (String string , int start ) {
10771077 boolean inExpression = false ;
1078- for (int i = start ; i < string .length (); i ++) {
1078+ int length = string .length ();
1079+ for (int i = start ; i < length ; i ++) {
10791080 char character = string .charAt (i );
10801081 if (character == '"' && !inExpression ) {
1081- if (i == string . length () - 1 || string .charAt (i + 1 ) != '"' )
1082+ if (i == length - 1 || string .charAt (i + 1 ) != '"' )
10821083 return i ;
10831084 i ++;
10841085 } else if (character == '%' ) {
@@ -1200,10 +1201,7 @@ public static int nextOccurrence(String haystack, String needle, int startIndex,
12001201 if (startIndex >= haystackLength )
12011202 return -1 ;
12021203
1203- if (!caseSensitive ) {
1204- haystack = haystack .toLowerCase (Locale .ENGLISH );
1205- needle = needle .toLowerCase (Locale .ENGLISH );
1206- }
1204+ int needleLength = needle .length ();
12071205
12081206 char firstChar = needle .charAt (0 );
12091207 boolean startsWithSpecialChar = firstChar == '"' || firstChar == '{' || firstChar == '(' ;
@@ -1212,9 +1210,11 @@ public static int nextOccurrence(String haystack, String needle, int startIndex,
12121210
12131211 char character = haystack .charAt (startIndex );
12141212
1215- if (startsWithSpecialChar ) { // Early check before special character handling
1216- if (haystack .startsWith (needle , startIndex ))
1217- return startIndex ;
1213+ if ( // Early check before special character handling
1214+ startsWithSpecialChar &&
1215+ haystack .regionMatches (!caseSensitive , startIndex , needle , 0 , needleLength )
1216+ ) {
1217+ return startIndex ;
12181218 }
12191219
12201220 switch (character ) {
@@ -1235,7 +1235,7 @@ public static int nextOccurrence(String haystack, String needle, int startIndex,
12351235 break ;
12361236 }
12371237
1238- if (haystack .startsWith ( needle , startIndex ))
1238+ if (haystack .regionMatches (! caseSensitive , startIndex , needle , 0 , needleLength ))
12391239 return startIndex ;
12401240
12411241 startIndex ++;
0 commit comments