101 |
|
|
102 |
/** |
/** |
103 |
* Stores unicode multi-character uppercase expansion table. |
* Stores unicode multi-character uppercase expansion table. |
104 |
* @see #toUpperCase(char) |
* @see #toUpperCase(Locale) |
105 |
* @see CharData#UPPER_EXPAND |
* @see CharData#UPPER_EXPAND |
106 |
*/ |
*/ |
107 |
private static final char[] upperExpand |
private static final char[] upperExpand |
142 |
final int offset; |
final int offset; |
143 |
|
|
144 |
/** |
/** |
145 |
* An implementation for {@link CASE_INSENSITIVE_ORDER}. |
* An implementation for {@link #CASE_INSENSITIVE_ORDER}. |
146 |
* This must be {@link Serializable}. The class name is dictated by |
* This must be {@link Serializable}. The class name is dictated by |
147 |
* compatibility with Sun's JDK. |
* compatibility with Sun's JDK. |
148 |
*/ |
*/ |
557 |
} |
} |
558 |
|
|
559 |
/** |
/** |
560 |
|
* Get the code point at the specified index. This is like #charAt(int), |
561 |
|
* but if the character is the start of a surrogate pair, and the |
562 |
|
* following character completes the pair, then the corresponding |
563 |
|
* supplementary code point is returned. |
564 |
|
* @param index the index of the codepoint to get, starting at 0 |
565 |
|
* @return the codepoint at the specified index |
566 |
|
* @throws IndexOutOfBoundsException if index is negative or >= length() |
567 |
|
* @since 1.5 |
568 |
|
*/ |
569 |
|
public synchronized int codePointAt(int index) |
570 |
|
{ |
571 |
|
// Use the CharSequence overload as we get better range checking |
572 |
|
// this way. |
573 |
|
return Character.codePointAt(this, index); |
574 |
|
} |
575 |
|
|
576 |
|
/** |
577 |
|
* Get the code point before the specified index. This is like |
578 |
|
* #codePointAt(int), but checks the characters at <code>index-1</code> and |
579 |
|
* <code>index-2</code> to see if they form a supplementary code point. |
580 |
|
* @param index the index just past the codepoint to get, starting at 0 |
581 |
|
* @return the codepoint at the specified index |
582 |
|
* @throws IndexOutOfBoundsException if index is negative or >= length() |
583 |
|
* (while unspecified, this is a StringIndexOutOfBoundsException) |
584 |
|
* @since 1.5 |
585 |
|
*/ |
586 |
|
public synchronized int codePointBefore(int index) |
587 |
|
{ |
588 |
|
// Use the CharSequence overload as we get better range checking |
589 |
|
// this way. |
590 |
|
return Character.codePointBefore(this, index); |
591 |
|
} |
592 |
|
|
593 |
|
/** |
594 |
* Copies characters from this String starting at a specified start index, |
* Copies characters from this String starting at a specified start index, |
595 |
* ending at a specified stop index, to a character array starting at |
* ending at a specified stop index, to a character array starting at |
596 |
* a specified destination begin index. |
* a specified destination begin index. |
665 |
ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count)); |
ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count)); |
666 |
if(bbuf.hasArray()) |
if(bbuf.hasArray()) |
667 |
return bbuf.array(); |
return bbuf.array(); |
668 |
|
|
669 |
// Doubt this will happen. But just in case. |
// Doubt this will happen. But just in case. |
670 |
byte[] bytes = new byte[bbuf.remaining()]; |
byte[] bytes = new byte[bbuf.remaining()]; |
671 |
bbuf.get(bytes); |
bbuf.get(bytes); |
672 |
return bytes; |
return bytes; |
673 |
|
} |
674 |
} catch(IllegalCharsetNameException e){ |
catch(IllegalCharsetNameException e) |
675 |
throw new UnsupportedEncodingException("Encoding: "+enc+ |
{ |
676 |
" not found."); |
throw new UnsupportedEncodingException("Encoding: " + enc |
677 |
} catch(UnsupportedCharsetException e){ |
+ " not found."); |
678 |
throw new UnsupportedEncodingException("Encoding: "+enc+ |
} |
679 |
" not found."); |
catch(UnsupportedCharsetException e) |
680 |
} catch(CharacterCodingException e){ |
{ |
681 |
// XXX - Ignore coding exceptions? They shouldn't really happen. |
throw new UnsupportedEncodingException("Encoding: " + enc |
682 |
return null; |
+ " not found."); |
683 |
|
} |
684 |
|
catch(CharacterCodingException e) |
685 |
|
{ |
686 |
|
// This shouldn't ever happen. |
687 |
|
throw (InternalError) new InternalError().initCause(e); |
688 |
} |
} |
689 |
} |
} |
690 |
|
|
768 |
} |
} |
769 |
|
|
770 |
/** |
/** |
771 |
|
* Compares the given CharSequence to this String. This is true if |
772 |
|
* the CharSequence has the same content as this String at this |
773 |
|
* moment. |
774 |
|
* |
775 |
|
* @param seq the CharSequence to compare to |
776 |
|
* @return true if CharSequence has the same character sequence |
777 |
|
* @throws NullPointerException if the given CharSequence is null |
778 |
|
* @since 1.5 |
779 |
|
*/ |
780 |
|
public boolean contentEquals(CharSequence seq) |
781 |
|
{ |
782 |
|
if (seq.length() != count) |
783 |
|
return false; |
784 |
|
for (int i = 0; i < count; ++i) |
785 |
|
if (value[offset + i] != seq.charAt(i)) |
786 |
|
return false; |
787 |
|
return true; |
788 |
|
} |
789 |
|
|
790 |
|
/** |
791 |
* Compares a String to this String, ignoring case. This does not handle |
* Compares a String to this String, ignoring case. This does not handle |
792 |
* multi-character capitalization exceptions; instead the comparison is |
* multi-character capitalization exceptions; instead the comparison is |
793 |
* made on a character-by-character basis, and is true if:<br><ul> |
* made on a character-by-character basis, and is true if:<br><ul> |
1723 |
} |
} |
1724 |
|
|
1725 |
/** |
/** |
1726 |
|
* Return the number of code points between two indices in the |
1727 |
|
* <code>StringBuffer</code>. An unpaired surrogate counts as a |
1728 |
|
* code point for this purpose. Characters outside the indicated |
1729 |
|
* range are not examined, even if the range ends in the middle of a |
1730 |
|
* surrogate pair. |
1731 |
|
* |
1732 |
|
* @param start the starting index |
1733 |
|
* @param end one past the ending index |
1734 |
|
* @return the number of code points |
1735 |
|
* @since 1.5 |
1736 |
|
*/ |
1737 |
|
public synchronized int codePointCount(int start, int end) |
1738 |
|
{ |
1739 |
|
if (start < 0 || end >= count || start > end) |
1740 |
|
throw new StringIndexOutOfBoundsException(); |
1741 |
|
|
1742 |
|
start += offset; |
1743 |
|
end += offset; |
1744 |
|
int count = 0; |
1745 |
|
while (start < end) |
1746 |
|
{ |
1747 |
|
char base = value[start]; |
1748 |
|
if (base < Character.MIN_HIGH_SURROGATE |
1749 |
|
|| base > Character.MAX_HIGH_SURROGATE |
1750 |
|
|| start == end |
1751 |
|
|| start == count |
1752 |
|
|| value[start + 1] < Character.MIN_LOW_SURROGATE |
1753 |
|
|| value[start + 1] > Character.MAX_LOW_SURROGATE) |
1754 |
|
{ |
1755 |
|
// Nothing. |
1756 |
|
} |
1757 |
|
else |
1758 |
|
{ |
1759 |
|
// Surrogate pair. |
1760 |
|
++start; |
1761 |
|
} |
1762 |
|
++start; |
1763 |
|
++count; |
1764 |
|
} |
1765 |
|
return count; |
1766 |
|
} |
1767 |
|
|
1768 |
|
/** |
1769 |
* Helper function used to detect which characters have a multi-character |
* Helper function used to detect which characters have a multi-character |
1770 |
* uppercase expansion. Note that this is only used in locations which |
* uppercase expansion. Note that this is only used in locations which |
1771 |
* track one-to-many capitalization (java.lang.Character does not do this). |
* track one-to-many capitalization (java.lang.Character does not do this). |