554 |
} |
} |
555 |
|
|
556 |
/** |
/** |
557 |
|
* Get the code point at the specified index. This is like #charAt(int), |
558 |
|
* but if the character is the start of a surrogate pair, and the |
559 |
|
* following character completes the pair, then the corresponding |
560 |
|
* supplementary code point is returned. |
561 |
|
* @param index the index of the codepoint to get, starting at 0 |
562 |
|
* @return the codepoint at the specified index |
563 |
|
* @throws IndexOutOfBoundsException if index is negative or >= length() |
564 |
|
* @since 1.5 |
565 |
|
*/ |
566 |
|
public synchronized int codePointAt(int index) |
567 |
|
{ |
568 |
|
// Use the CharSequence overload as we get better range checking |
569 |
|
// this way. |
570 |
|
return Character.codePointAt(this, index); |
571 |
|
} |
572 |
|
|
573 |
|
/** |
574 |
|
* Get the code point before the specified index. This is like |
575 |
|
* #codePointAt(int), but checks the characters at <code>index-1</code> and |
576 |
|
* <code>index-2</code> to see if they form a supplementary code point. |
577 |
|
* @param index the index just past the codepoint to get, starting at 0 |
578 |
|
* @return the codepoint at the specified index |
579 |
|
* @throws IndexOutOfBoundsException if index is negative or >= length() |
580 |
|
* (while unspecified, this is a StringIndexOutOfBoundsException) |
581 |
|
* @since 1.5 |
582 |
|
*/ |
583 |
|
public synchronized int codePointBefore(int index) |
584 |
|
{ |
585 |
|
// Use the CharSequence overload as we get better range checking |
586 |
|
// this way. |
587 |
|
return Character.codePointBefore(this, index); |
588 |
|
} |
589 |
|
|
590 |
|
/** |
591 |
* Copies characters from this String starting at a specified start index, |
* Copies characters from this String starting at a specified start index, |
592 |
* ending at a specified stop index, to a character array starting at |
* ending at a specified stop index, to a character array starting at |
593 |
* a specified destination begin index. |
* a specified destination begin index. |
765 |
} |
} |
766 |
|
|
767 |
/** |
/** |
768 |
|
* Compares the given CharSequence to this String. This is true if |
769 |
|
* the CharSequence has the same content as this String at this |
770 |
|
* moment. |
771 |
|
* |
772 |
|
* @param seq the CharSequence to compare to |
773 |
|
* @return true if CharSequence has the same character sequence |
774 |
|
* @throws NullPointerException if the given CharSequence is null |
775 |
|
* @since 1.5 |
776 |
|
*/ |
777 |
|
public boolean contentEquals(CharSequence seq) |
778 |
|
{ |
779 |
|
if (seq.length() != count) |
780 |
|
return false; |
781 |
|
for (int i = 0; i < count; ++i) |
782 |
|
if (value[offset + i] != seq.charAt(i)) |
783 |
|
return false; |
784 |
|
return true; |
785 |
|
} |
786 |
|
|
787 |
|
/** |
788 |
* Compares a String to this String, ignoring case. This does not handle |
* Compares a String to this String, ignoring case. This does not handle |
789 |
* multi-character capitalization exceptions; instead the comparison is |
* multi-character capitalization exceptions; instead the comparison is |
790 |
* 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> |
1736 |
} |
} |
1737 |
|
|
1738 |
/** |
/** |
1739 |
|
* Return the number of code points between two indices in the |
1740 |
|
* <code>StringBuffer</code>. An unpaired surrogate counts as a |
1741 |
|
* code point for this purpose. Characters outside the indicated |
1742 |
|
* range are not examined, even if the range ends in the middle of a |
1743 |
|
* surrogate pair. |
1744 |
|
* |
1745 |
|
* @param start the starting index |
1746 |
|
* @param end one past the ending index |
1747 |
|
* @return the number of code points |
1748 |
|
* @since 1.5 |
1749 |
|
*/ |
1750 |
|
public synchronized int codePointCount(int start, int end) |
1751 |
|
{ |
1752 |
|
if (start < 0 || end >= count || start > end) |
1753 |
|
throw new StringIndexOutOfBoundsException(); |
1754 |
|
|
1755 |
|
start += offset; |
1756 |
|
end += offset; |
1757 |
|
int count = 0; |
1758 |
|
while (start < end) |
1759 |
|
{ |
1760 |
|
char base = value[start]; |
1761 |
|
if (base < Character.MIN_HIGH_SURROGATE |
1762 |
|
|| base > Character.MAX_HIGH_SURROGATE |
1763 |
|
|| start == end |
1764 |
|
|| start == count |
1765 |
|
|| value[start + 1] < Character.MIN_LOW_SURROGATE |
1766 |
|
|| value[start + 1] > Character.MAX_LOW_SURROGATE) |
1767 |
|
{ |
1768 |
|
// Nothing. |
1769 |
|
} |
1770 |
|
else |
1771 |
|
{ |
1772 |
|
// Surrogate pair. |
1773 |
|
++start; |
1774 |
|
} |
1775 |
|
++start; |
1776 |
|
++count; |
1777 |
|
} |
1778 |
|
return count; |
1779 |
|
} |
1780 |
|
|
1781 |
|
/** |
1782 |
* Helper function used to detect which characters have a multi-character |
* Helper function used to detect which characters have a multi-character |
1783 |
* uppercase expansion. Note that this is only used in locations which |
* uppercase expansion. Note that this is only used in locations which |
1784 |
* track one-to-many capitalization (java.lang.Character does not do this). |
* track one-to-many capitalization (java.lang.Character does not do this). |