subSequence() private méthode

private subSequence ( int par0, int par1 ) : global::java.lang.CharSequence
par0 int
par1 int
Résultat global::java.lang.CharSequence
Exemple #1
0
        /**
         * Attempts to find the next subsequence in the searched sequence on or after {@code searchIndex}
         * that represents a phone number. Returns the next match, null if none was found.
         *
         * @param index  the search index to start searching at
         * @return  the phone number match found, null if none can be found
         */
        private PhoneNumberMatch find(int index)
        {
            Matcher matcher = PATTERN.matcher(text);

            while ((maxTries > 0) && matcher.find(index))
            {
                int          start     = matcher.start();
                CharSequence candidate = text.subSequence(start, matcher.end());

                // Check for extra numbers at the end.
                // TODO: This is the place to start when trying to support extraction of multiple phone number
                // from split notations (+41 79 123 45 67 / 68).
                candidate = trimAfterFirstMatch(PhoneNumberUtil.SECOND_NUMBER_START_PATTERN, candidate);

                PhoneNumberMatch match = extractMatch(candidate, start);
                if (match != null)
                {
                    return(match);
                }

                index = start + candidate.length();
                maxTries--;
            }

            return(null);
        }
Exemple #2
0
        /**
         * Trims away any characters after the first match of {@code pattern} in {@code candidate},
         * returning the trimmed version.
         */
        private static CharSequence trimAfterFirstMatch(Pattern pattern, CharSequence candidate)
        {
            Matcher trailingCharsMatcher = pattern.matcher(candidate);

            if (trailingCharsMatcher.find())
            {
                candidate = candidate.subSequence(0, trailingCharsMatcher.start());
            }
            return(candidate);
        }