2222 * or visit www.oracle.com if you need additional information or have any
2323 * questions.
2424 */
25-
2625package robaho .net .httpserver ;
2726
2827/**
@@ -36,9 +35,9 @@ public class Utils {
3635 private static final boolean [] QUOTED_PAIR = new boolean [256 ];
3736
3837 static {
39- char [] allowedTokenChars = ("!#$%&'*+-.^_`|~0123456789" +
40- "abcdefghijklmnopqrstuvwxyz" +
41- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ).toCharArray ();
38+ char [] allowedTokenChars = ("!#$%&'*+-.^_`|~0123456789"
39+ + "abcdefghijklmnopqrstuvwxyz"
40+ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ).toCharArray ();
4241 for (char c : allowedTokenChars ) {
4342 TCHAR [c ] = true ;
4443 }
@@ -87,4 +86,32 @@ public static boolean isQuotedStringContent(String token) {
8786 }
8887 return true ;
8988 }
89+
90+ /**
91+ * efficient contains() ignoring case
92+ */
93+ public static boolean containsIgnoreCase (String src , String what ) {
94+ final int length = what .length ();
95+ if (length == 0 ) {
96+ return true ; // Empty string is contained
97+ }
98+ final char firstLo = Character .toLowerCase (what .charAt (0 ));
99+ final char firstUp = Character .toUpperCase (what .charAt (0 ));
100+
101+ final int srcLength = src .length ();
102+
103+ for (int i = srcLength - length ; i >= 0 ; i --) {
104+ // Quick check before calling the more expensive regionMatches() method:
105+ final char ch = src .charAt (i );
106+ if (ch != firstLo && ch != firstUp ) {
107+ continue ;
108+ }
109+
110+ if (src .regionMatches (true , i , what , 0 , length )) {
111+ return true ;
112+ }
113+ }
114+
115+ return false ;
116+ }
90117}
0 commit comments