ICU-2990 code review changes

X-SVN-Rev: 13799
This commit is contained in:
Markus Scherer 2003-11-21 00:55:04 +00:00
parent 43aca775e3
commit 08b4557e06
2 changed files with 24 additions and 7 deletions

View File

@ -232,13 +232,19 @@ uiter_setString(UCharIterator *iter, const UChar *s, int32_t length) {
* except that UChars are assembled from byte pairs.
*/
/* internal helper function */
static inline UChar32
utf16BEIteratorGet(UCharIterator *iter, int32_t index) {
const uint8_t *p=(const uint8_t *)iter->context;
return ((UChar)p[2*index]<<8)|(UChar)p[2*index+1];
}
static UChar32 U_CALLCONV
utf16BEIteratorCurrent(UCharIterator *iter) {
int32_t index;
if((index=iter->index)<iter->limit) {
const uint8_t *p=(const uint8_t *)iter->context;
return ((UChar)p[2*index]<<8)|(UChar)p[2*index+1];
return utf16BEIteratorGet(iter, index);
} else {
return U_SENTINEL;
}
@ -249,9 +255,8 @@ utf16BEIteratorNext(UCharIterator *iter) {
int32_t index;
if((index=iter->index)<iter->limit) {
const uint8_t *p=(const uint8_t *)iter->context;
iter->index=index+1;
return ((UChar)p[2*index]<<8)|(UChar)p[2*index+1];
return utf16BEIteratorGet(iter, index);
} else {
return U_SENTINEL;
}
@ -262,9 +267,8 @@ utf16BEIteratorPrevious(UCharIterator *iter) {
int32_t index;
if((index=iter->index)>iter->start) {
const uint8_t *p=(const uint8_t *)iter->context;
iter->index=--index;
return ((UChar)p[2*index]<<8)|(UChar)p[2*index+1];
return utf16BEIteratorGet(iter, index);
} else {
return U_SENTINEL;
}
@ -840,7 +844,7 @@ utf8IteratorMove(UCharIterator *iter, int32_t delta, UCharIteratorOrigin origin)
static UBool U_CALLCONV
utf8IteratorHasNext(UCharIterator *iter) {
return iter->reservedField!=0 || iter->start<iter->limit;
return iter->start<iter->limit || iter->reservedField!=0;
}
static UBool U_CALLCONV

View File

@ -242,6 +242,10 @@ UCharIteratorReserved(UCharIterator *iter, int32_t something);
* to save and restore the iterator position more efficiently than with
* getIndex()/move().
*
* The iterator state is defined as a uint32_t value because it is designed
* for use in ucol_nextSortKeyPart() which provides 32 bits to store the state
* of the character iterator.
*
* With some UCharIterator implementations (e.g., UTF-8),
* getting and setting the UTF-16 index with existing functions
* (getIndex(UITER_CURRENT) followed by move(pos, UITER_ZERO)) is possible but
@ -317,6 +321,15 @@ UCharIteratorSetState(UCharIterator *iter, uint32_t state, UErrorCode *pErrorCod
* they only use the "public" function pointers and never access the "protected"
* fields directly.
*
* The current() and next() functions only check the current index against the
* limit, and previous() only checks the current index against the start,
* to see if the iterator already reached the end of the iteration range.
*
* The assumption - in all iterators - is that the index is moved via the API,
* which means it won't go out of bounds, or the index is modified by
* user code that knows enough about the iterator implementation to set valid
* index values.
*
* UCharIterator functions return code unit values 0..0xffff,
* or U_SENTINEL if the iteration bounds are reached.
*