]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/unorm_it.c
ICU-461.18.tar.gz
[apple/icu.git] / icuSources / common / unorm_it.c
index 83e0d15dced1f38e956ae1e7294e229d9994b61f..00396bd6daa4f76f07a58f5483bd0c1de132969f 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2003, International Business Machines
+*   Copyright (C) 2003-2008, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -137,7 +137,7 @@ moveContentsTowardStart(UCharIterator *api, UChar chars[], uint32_t states[], in
     srcIndex=delta;
     if(srcIndex>api->start) {
         /* look for a position in the arrays with a known state */
-        while(srcIndex<limit && chars[srcIndex]==UITER_NO_STATE) {
+        while(srcIndex<limit && states[srcIndex]==UITER_NO_STATE) {
             ++srcIndex;
         }
     }
@@ -165,7 +165,7 @@ moveContentsTowardEnd(UCharIterator *api, UChar chars[], uint32_t states[], int3
     srcIndex=destIndex-delta;
     if(srcIndex<api->limit) {
         /* look for a position in the arrays with a known state */
-        while(srcIndex>start && chars[srcIndex]==UITER_NO_STATE) {
+        while(srcIndex>start && states[srcIndex]==UITER_NO_STATE) {
             --srcIndex;
         }
     }
@@ -191,16 +191,15 @@ readNext(UNormIterator *uni, UCharIterator *iter) {
     UCharIterator *api=&uni->api;
 
     /* make capacity/4 room at the end of the arrays */
-    int32_t limit, capacity, room, delta;
+    int32_t limit, capacity, room;
     UErrorCode errorCode;
 
     limit=api->limit;
     capacity=uni->capacity;
     room=capacity/4;
-    delta=room-(capacity-limit);
-    if(delta>0) {
+    if(room>(capacity-limit)) {
         /* move array contents to make room */
-        moveContentsTowardStart(api, uni->chars, uni->states, delta);
+        moveContentsTowardStart(api, uni->chars, uni->states, room);
         api->index=limit=api->limit;
         uni->hasPrevious=TRUE;
     }
@@ -262,16 +261,15 @@ readPrevious(UNormIterator *uni, UCharIterator *iter) {
     UCharIterator *api=&uni->api;
 
     /* make capacity/4 room at the start of the arrays */
-    int32_t start, capacity, room, delta;
+    int32_t start, capacity, room;
     UErrorCode errorCode;
 
     start=api->start;
     capacity=uni->capacity;
     room=capacity/4;
-    delta=room-start;
-    if(delta>0) {
+    if(room>start) {
         /* move array contents to make room */
-        moveContentsTowardEnd(api, uni->chars, uni->states, delta);
+        moveContentsTowardEnd(api, uni->chars, uni->states, room);
         api->index=start=api->start;
         uni->hasNext=TRUE;
     }
@@ -559,16 +557,17 @@ unorm_openIter(void *stackMem, int32_t stackMemSize, UErrorCode *pErrorCode) {
     /* allocate */
     uni=NULL;
     if(stackMem!=NULL && stackMemSize>=sizeof(UNormIterator)) {
-        size_t align=U_ALIGNMENT_OFFSET(stackMem);
-        if(align==0) {
+        if(U_ALIGNMENT_OFFSET(stackMem)==0) {
             /* already aligned */
             uni=(UNormIterator *)stackMem;
-        } else if((stackMemSize-=align)>=sizeof(UNormIterator)) {
-            /* needs alignment */
-            uni=(UNormIterator *)((char *)stackMem+align);
         } else {
-            /* does not fit */
+            int32_t align=(int32_t)U_ALIGNMENT_OFFSET_UP(stackMem);
+            if((stackMemSize-=align)>=(int32_t)sizeof(UNormIterator)) {
+                /* needs alignment */
+                uni=(UNormIterator *)((char *)stackMem+align);
+            }
         }
+        /* else does not fit */
     }
 
     if(uni!=NULL) {