/** * Attempts to extract a match from a {@code candidate} character sequence. * * @param candidate the candidate text that might contain a phone number * @param offset the offset of {@code candidate} within {@link #text} * @return the match found, null if none can be found */ private PhoneNumberMatch extractMatch(CharSequence candidate, int offset) { // Skip a match that is more likely a publication page reference or a date. if (PUB_PAGES.matcher(candidate).find() || SLASH_SEPARATED_DATES.matcher(candidate).find()) { return(null); } // Skip potential time-stamps. if (TIME_STAMPS.matcher(candidate).find()) { String followingText = text.toString().substring(offset + candidate.length()); if (TIME_STAMPS_SUFFIX.matcher(followingText).lookingAt()) { return(null); } } // Try to come up with a valid match given the entire candidate. String rawString = candidate.toString(); PhoneNumberMatch match = parseAndVerify(rawString, offset); if (match != null) { return(match); } // If that failed, try to find an "inner match" - there might be a phone number within this // candidate. return(extractInnerMatch(rawString, offset)); }
/** * Attempts to extract a match from {@code candidate} if the whole candidate does not qualify as a * match. * * @param candidate the candidate text that might contain a phone number * @param offset the current offset of {@code candidate} within {@link #text} * @return the match found, null if none can be found */ private PhoneNumberMatch extractInnerMatch(String candidate, int offset) { // Try removing either the first or last "group" in the number and see if this gives a result. // We consider white space to be a possible indication of the start or end of the phone number. Matcher groupMatcher = GROUP_SEPARATOR.matcher(candidate); if (groupMatcher.find()) { // Try the first group by itself. CharSequence firstGroupOnly = candidate.substring(0, groupMatcher.start()); firstGroupOnly = trimAfterFirstMatch(PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN, firstGroupOnly); PhoneNumberMatch match = parseAndVerify(firstGroupOnly.toString(), offset); if (match != null) { return(match); } maxTries--; int withoutFirstGroupStart = groupMatcher.end(); // Try the rest of the candidate without the first group. CharSequence withoutFirstGroup = candidate.substring(withoutFirstGroupStart); withoutFirstGroup = trimAfterFirstMatch(PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN, withoutFirstGroup); match = parseAndVerify(withoutFirstGroup.toString(), offset + withoutFirstGroupStart); if (match != null) { return(match); } maxTries--; if (maxTries > 0) { int lastGroupStart = withoutFirstGroupStart; while (groupMatcher.find()) { // Find the last group. lastGroupStart = groupMatcher.start(); } CharSequence withoutLastGroup = candidate.substring(0, lastGroupStart); withoutLastGroup = trimAfterFirstMatch(PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN, withoutLastGroup); if (withoutLastGroup.equals(firstGroupOnly)) { // If there are only two groups, then the group "without the last group" is the same as // the first group. In these cases, we don't want to re-check the number group, so we exit // already. return(null); } match = parseAndVerify(withoutLastGroup.toString(), offset); if (match != null) { return(match); } maxTries--; } } return(null); }
public static void crash(int i, JniGlobalHandle handle) { //Console.WriteLine("a" + i); var sharedBuffer = new byte[10 * 1024 * 100]; //Console.WriteLine("b"); DirectByteBuffer execJavaBuffer = new DirectByteBuffer(sharedBuffer); //Console.WriteLine("c"); try { String duplicate = Bridge.CreateProxy <String>(handle); string s = duplicate.toString(); } catch (System.Exception) { Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); throw; } //Console.WriteLine("d"); GC.Collect(3, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); }