Example #1
0
        public boolean contentEquals(CharSequence cs)
        {
            if (value.Length != cs.length())
            {
                return(false);
            }
            // Argument is a StringBuffer, StringBuilder
            //if (cs is StringBuilder) {
            //    char[] v1 = value;
            //    char[] v2 = ((AbstractStringBuilder) cs).getValue();
            //    int i = 0;
            //    int n = value.Length;
            //    while (n-- != 0) {
            //        if (v1[i] != v2[i])
            //            return false;
            //        i++;
            //    }
            //    return true;
            //}
            // Argument is a String
            if (cs.Equals(this))
            {
                return(true);
            }
            // Argument is a generic CharSequence
            char[] _v1 = value;
            int    _i  = 0;
            int    _n  = value.Length;

            while (_n-- != 0)
            {
                if (_v1[_i] != cs.charAt(_i))
                {
                    return(false);
                }
                _i++;
            }
            return(true);
        }
 public StringBuilder(CharSequence seq)
     : base(seq.length() + 16)
 {
     append(seq);
 }
 public StringBuffer(CharSequence seq) : base(seq.length() + 16)
 {
     append(seq);
 }
 public String[] split(CharSequence input, int limit) {
     int index = 0;
     boolean matchLimited = limit > 0;
     ArrayList<String> matchList = new ArrayList<String>();
     Matcher m = matcher(input);
     // Add segments before each match found
     while(m.find()) {
         if (!matchLimited || matchList.size() < limit - 1) {
             String match = input.subSequence(index, m.start()).toString();
             matchList.add(match);
             index = m.end();
         } else if (matchList.size() == limit - 1) { // last one
             String match = input.subSequence(index,
                                              input.length()).toString();
             matchList.add(match);
             index = m.end();
         }
     }
     // If no match was found, return this
     if (index == 0)
         return new String[] {input.toString()};
     // Add remaining segment
     if (!matchLimited || matchList.size() < limit)
         matchList.add(input.subSequence(index, input.length()).toString());
     // Construct result
     int resultSize = matchList.size();
     if (limit == 0)
         while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
             resultSize--;
     String[] result = new String[resultSize];
     return matchList.subList(0, resultSize).toArray(result);
 }
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     if (i > matcher.to - minLength) {
         matcher._hitEnd = true;
         return false;
     }
     int guard = matcher.to - minLength;
     while (i <= guard) {
         //if ((ret = next.match(matcher, i, seq)) || i == guard)
         if (next.match(matcher, i, seq)) {
             matcher.first = i;
             matcher.groups[0] = matcher.first;
             matcher.groups[1] = matcher.last;
             return true;
         }
         if (i == guard)
             break;
         // Optimization to move to the next character. This is
         // faster than countChars(seq, i, 1).
         if (Character.isHighSurrogate(seq.charAt(i++))) {
             if (i < seq.length() &&
                 Character.isLowSurrogate(seq.charAt(i))) {
                 i++;
             }
         }
     }
     matcher._hitEnd = true;
     return false;
 }
 private static int countCodePoints(CharSequence seq) {
     int length = seq.length();
     int n = 0;
     for (int i = 0; i < length; ) {
         n++;
         if (Character.isHighSurrogate(seq.charAt(i++))) {
             if (i < length && Character.isLowSurrogate(seq.charAt(i))) {
                 i++;
             }
         }
     }
     return n;
 }
 //
 // Utility methods for code point support
 //
 private static int countChars(CharSequence seq, int index,
                                     int lengthInCodePoints) {
     // optimization
     if (lengthInCodePoints == 1 && !Character.isHighSurrogate(seq.charAt(index))) {
         return 1;
     }
     int length = seq.length();
     int x = index;
     if (lengthInCodePoints >= 0) {
         for (int i = 0; x < length && i < lengthInCodePoints; i++) {
             if (Character.isHighSurrogate(seq.charAt(x++))) {
                 if (x < length && Character.isLowSurrogate(seq.charAt(x))) {
                     x++;
                 }
             }
         }
         return x - index;
     }
     if (index == 0) {
         return 0;
     }
     int len = -lengthInCodePoints;
     for (int i = 0; x > 0 && i < len; i++) {
         if (Character.isLowSurrogate(seq.charAt(--x))) {
             if (x > 0 && Character.isHighSurrogate(seq.charAt(x-1))) {
                 x--;
             }
         }
     }
     return index - x;
 }
 /**
    * Asserts that another number can be found in {@code text} starting at {@code index}, and that
    * its corresponding range is {@code [start, end)}.
    */
 private void assertEqualRange(CharSequence text, int index, int start, int end)
 {
     CharSequence sub = text.subSequence(index, text.length());
     Iterator<PhoneNumberMatch> matches =
       phoneUtil.findNumbers(sub, RegionCode.NZ, Leniency.POSSIBLE, Long.MAX_VALUE).iterator();
     assertTrue(matches.hasNext());
     PhoneNumberMatch match = matches.next();
     assertEquals(start - index, match.start());
     assertEquals(end - index, match.end());
     assertEquals(sub.subSequence(match.start(), match.end()).toString(), match.rawString());
 }