ICU-1267 add UnicodeString::countChar32()

X-SVN-Rev: 6197
This commit is contained in:
Markus Scherer 2001-10-11 21:40:24 +00:00
parent 0df9c9daf8
commit 6fb93470d2
2 changed files with 22 additions and 0 deletions

View File

@ -1390,6 +1390,21 @@ public:
*/
inline int32_t length(void) const;
/**
* Count Unicode code points in the length UChar code units of the string.
* A code point may occupy either one or two UChar code units.
* Counting code points involves reading all code units.
*
* This functions is basically the inverse of moveIndex32().
*
* @param start the index of the first code unit to check
* @param length the number of UChar code units to check
* @return the number of code points in the specified code units
* @draft ICU 2.0
*/
int32_t
countChar32(UTextOffset start=0, int32_t length=0x7fffffff) const;
/**
* Determine if this string is empty.
* @return TRUE if this string contains 0 characters, FALSE otherwise.

View File

@ -675,6 +675,13 @@ UnicodeString::getChar32At(UTextOffset offset) const {
return char32At(offset);
}
int32_t
UnicodeString::countChar32(UTextOffset start, int32_t length) const {
pinIndices(start, length);
// if(isBogus()) then fArray==0 and start==0 - u_countChar32() checks for NULL
return u_countChar32(fArray+start, length);
}
UTextOffset
UnicodeString::moveIndex32(UTextOffset index, int32_t delta) const {
// pin index