1 19 20 package org.netbeans.modules.derby; 21 22 26 public class SearchUtil { 27 28 static final int FOUND = -1; 29 30 33 static int checkForString(String searchedFor, int searchStart, char[] buf, int bufLen) { 34 if (searchedFor.length() == 0) 35 throw new IllegalArgumentException (); 36 if (searchStart > 0) { 37 int res = checkPosition(searchedFor, searchStart, buf, bufLen, 0); 39 if (res == FOUND) 40 return FOUND; 41 } 42 for (int i = 0; i < bufLen; i++) { 43 if (buf[i] == searchedFor.charAt(searchStart)) { 44 int res = checkPosition(searchedFor, 0, buf, bufLen, i); 46 if (res != 0) 47 return res; 48 } 49 } 50 return 0; 51 } 52 53 58 static int checkPosition(String searchedFor, int searchStart, char[] buf, int bufLen, int bufFrom) { 59 String realSearch = searchedFor.substring(searchStart); 60 for (int i = 0; i < realSearch.length(); i++) { 61 int bufPos = bufFrom + i; 62 if (bufPos >= bufLen) { 63 return searchStart + i; 64 } 65 if (buf[bufPos] != realSearch.charAt(i)) 66 return 0; 67 } 68 return FOUND; 69 } 70 71 72 } 73 | Popular Tags |