List of usage examples for java.lang String regionMatches
public boolean regionMatches(int toffset, String other, int ooffset, int len)
From source file:Main.java
public static void main(String[] args) { String str1 = "tutorials from java2s.com"; String str2 = "Java tutorials from java2s.com"; boolean match1 = str1.regionMatches(14, str2, 22, 9); System.out.println("region matched = " + match1); System.out.println("region matched = " + match1); }
From source file:RegionMatchesDemo.java
public static void main(String[] args) { String searchMe = "Green Eggs and Ham"; String findMe = "Eggs"; int len = findMe.length(); boolean foundIt = false; int i = 0;/* www. j av a2 s . c o m*/ while (!searchMe.regionMatches(i, findMe, 0, len)) { i++; foundIt = true; } if (foundIt) { System.out.println(searchMe.substring(i, i + len)); } }
From source file:Main.java
public static void main(String[] args) { String searchMe = "Green Eggs and Ham"; String findMe = "Eggs"; int searchMeLength = searchMe.length(); int findMeLength = findMe.length(); boolean foundIt = false; for (int i = 0; i <= (searchMeLength - findMeLength); i++) { if (searchMe.regionMatches(i, findMe, 0, findMeLength)) { foundIt = true;/*from ww w . j av a 2s .c o m*/ System.out.println(searchMe.substring(i, i + findMeLength)); break; } } if (!foundIt) System.out.println("No match found."); }
From source file:Main.java
private static boolean isStartOf(String xml, int i, String substring) { return xml.regionMatches(i, substring, 0, substring.length()); }
From source file:Main.java
private static boolean hasDotChar(String path) { int idot = 0; while (idot != -1) { idot = path.indexOf('.', idot); if (idot != -1) { if (path.regionMatches(idot, "../", 0, 3)) { idot += 3;// w w w . j a v a 2s. c o m } else if (path.regionMatches(idot, "./", 0, 2)) { idot += 2; } else { return true; } } } return false; }
From source file:Main.java
/** * Strip off the end portion of the name. The user might be typing * the activity name such that only a portion has been entered so far (e.g. * "MainActivi") and we want to chop off that portion too such that we don't * offer a layout name partially containing the activity suffix (e.g. "main_activi"). *///from w w w. j a v a 2 s . co m public static String stripSuffix(String name, String suffix, boolean recursiveStrip) { if (name.isEmpty()) { return name; } int suffixStart = name.lastIndexOf(suffix.charAt(0)); if (suffixStart != -1 && name.regionMatches(suffixStart, suffix, 0, name.length() - suffixStart)) { name = name.substring(0, suffixStart); } // Recursively continue to strip the suffix (catch the FooActivityActivity case) if (recursiveStrip && name.endsWith(suffix)) { return stripSuffix(name, suffix, recursiveStrip); } return name; }
From source file:Main.java
/** * Strip off the end portion of the name. The user might be typing * the activity name such that only a portion has been entered so far (e.g. * "MainActivi") and we want to chop off that portion too such that we don't * offer a layout name partially containing the activity suffix (e.g. "main_activi"). *///from w w w . j ava2s .co m public static String stripSuffix(String name, String suffix, boolean recursiveStrip) { if (name.length() < 2) { return name; } int suffixStart = name.lastIndexOf(suffix.charAt(0)); if (suffixStart != -1 && name.regionMatches(suffixStart, suffix, 0, name.length() - suffixStart)) { name = name.substring(0, suffixStart); } // Recursively continue to strip the suffix (catch the FooActivityActivity case) if (recursiveStrip && name.endsWith(suffix)) { return stripSuffix(name, suffix, recursiveStrip); } return name; }
From source file:org.melati.login.HttpAuthorization.java
/** * Create an Authorization from an HTTP Authorization header. * /*from ww w . j a v a 2 s . c o m*/ * @param authHeader * @return a new Authorization or null */ static HttpAuthorization from(String authHeader) { // Space is only valid separator, // from my reading of http://www.ietf.org/rfc/rfc2617.txt // only one. // This has worked well for a long time. if (authHeader.regionMatches(0, "Basic ", 0, 6)) { String logpas = new String(Base64.decodeBase64(authHeader.substring(6).getBytes())); int colon = logpas.indexOf(':'); if (colon == -1) throw new HttpAuthorizationMelatiException( "The browser sent Basic Authorization credentials with no colon " + "(that's not legal)"); return new HttpAuthorization("Basic", logpas.substring(0, colon).trim(), logpas.substring(colon + 1).trim()); } else { int space = authHeader.indexOf(' '); if (space == -1) throw new HttpAuthorizationMelatiException( "The browser sent an Authorization header without a space, " + "so it can't be anything Melati understands: " + authHeader); String type = authHeader.substring(0, space); throw new HttpAuthorizationMelatiException( "The browser tried to authenticate using an authorization type " + "`" + type + "' which Melati doesn't understand"); } }
From source file:Util.java
public static String longestStartingMatch(String source1, String source2) { /**/*ww w. j a va2s . c om*/ * I starting with the regex lookingAt() but it wasn't working for the test * cases I had (comparison of BigDecimals... DaC seems to work ok. */ int min = 0; int max = source1.length(); int cur = max / 2; while (true) { if (source2.regionMatches(0, source1, 0, cur)) { min = cur; cur += (max - cur) / 2; if (cur == min) { if (source2.regionMatches(0, source1, 0, max)) cur = max; break; } } else { max = cur; cur -= (cur - min) / 2; if (cur == max) { if (source2.regionMatches(0, source1, 0, min)) cur = min; break; } } } return source2.substring(0, cur); }
From source file:org.opendatakit.aggregate.form.PropertyMapSerializer.java
/** * Deserialize the XML representation for a key-value map. * * @param parameterDocument/*w ww. j a v a 2 s.co m*/ * @return parameter map as a Map<String,String> key-value map. */ public static Map<String, String> deserializeRequestParameters(String parameterDocument) { Map<String, String> parameters = new HashMap<String, String>(); if (parameterDocument == null) return parameters; if (!parameterDocument.startsWith(K_XML_BEGIN_PARAMETERS)) { throw new IllegalArgumentException( "bad parameter list -- not beginning with " + K_XML_BEGIN_PARAMETERS); } int iNext = K_XML_BEGIN_PARAMETERS.length(); while (parameterDocument.regionMatches(iNext, K_XML_BEGIN_PARAMETER_BEGIN_KEY, 0, K_XML_BEGIN_PARAMETER_BEGIN_KEY.length())) { iNext += K_XML_BEGIN_PARAMETER_BEGIN_KEY.length(); int iEnd = parameterDocument.indexOf(K_XML_END_KEY_BEGIN_VALUE, iNext); if (iEnd == -1) { throw new IllegalArgumentException("bad parameter list -- end-key-begin-value not found"); } String key = StringEscapeUtils.unescapeXml(parameterDocument.substring(iNext, iEnd)); iNext = iEnd + K_XML_END_KEY_BEGIN_VALUE.length(); iEnd = parameterDocument.indexOf(K_XML_END_VALUE_END_PARAMETER, iNext); if (iEnd == -1) { throw new IllegalArgumentException("bad parameter list -- end-value-end-parameter not found"); } String value = StringEscapeUtils.unescapeXml(parameterDocument.substring(iNext, iEnd)); iNext = iEnd + K_XML_END_VALUE_END_PARAMETER.length(); parameters.put(key, value); } if (!parameterDocument.regionMatches(iNext, K_XML_END_PARAMETERS, 0, K_XML_END_PARAMETERS.length())) { throw new IllegalArgumentException("bad parameter list -- end-parameters not found"); } iNext += K_XML_END_PARAMETERS.length(); if (iNext != parameterDocument.length()) { throw new IllegalArgumentException("bad parameter list -- extra characters found"); } return parameters; }