]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/citrtest.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / citrtest.cpp
index 8f2059fb7c972ed5fc044c02d4ebed6f11ca7f63..84a2b69ee09491e8b2e5d8890e8b6fecbbedb483 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /****************************************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2010, International Business Machines Corporation and
+ * Copyright (c) 1997-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
  * Modification History:
  *
@@ -9,7 +11,7 @@
  ****************************************************************************************/
 
 #include <string.h>
-#include <typeinfo>  // for 'typeid' to work
+#include "utypeinfo.h"  // for 'typeid' to work
 
 #include "unicode/chariter.h"
 #include "unicode/ustring.h"
@@ -18,7 +20,9 @@
 #include "unicode/uchriter.h"
 #include "unicode/uiter.h"
 #include "unicode/putil.h"
+#include "unicode/utf16.h"
 #include "citrtest.h"
+#include "cmemory.h"
 
 
 class  SCharacterIterator : public CharacterIterator {
@@ -102,20 +106,20 @@ public:
         case kStart:
             pos = begin;
             if(delta > 0) {
-                UTF_FWD_N(text, pos, end, delta);
+                U16_FWD_N(text, pos, end, delta);
             }
             break;
         case kCurrent:
             if(delta > 0) {
-                UTF_FWD_N(text, pos, end, delta);
+                U16_FWD_N(text, pos, end, delta);
             } else {
-                UTF_BACK_N(text, begin, pos, -delta);
+                U16_BACK_N(text, begin, pos, -delta);
             }
             break;
         case kEnd:
             pos = end;
             if(delta < 0) {
-                UTF_BACK_N(text, begin, pos, -delta);
+                U16_BACK_N(text, begin, pos, -delta);
             }
             break;
         default:
@@ -138,8 +142,6 @@ private:
 };
 const char SCharacterIterator::fgClassID=0;
 
-#define LENGTHOF(array) ((int32_t)(sizeof(array)/sizeof((array)[0])))
-
 CharIterTest::CharIterTest()
 {
 }
@@ -609,7 +611,7 @@ void CharIterTest::TestIterationUChar32() {
                 errln("setIndex32() isn't working right");
             if (c != CharacterIterator::DONE) {
                 c = iter.next32();
-                i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1;
+                i += U16_LENGTH(c);
             }
         } while (c != CharacterIterator::DONE);
         if(iter.hasNext() == TRUE)
@@ -648,7 +650,7 @@ void CharIterTest::TestIterationUChar32() {
                 errln("getIndex() isn't working right");
             if (c != CharacterIterator::DONE) {
                 c = iter.previous32();
-                i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1;
+                i -= U16_LENGTH(c);
             }
         } while (c != CharacterIterator::DONE);
         if(iter.hasPrevious() == TRUE)
@@ -666,7 +668,7 @@ void CharIterTest::TestIterationUChar32() {
         c=iter.first32PostInc();
         if(c != text.char32At(i))
             errln("first32PostInc failed.  Expected->%X Got->%X", text.char32At(i), c);
-        if(iter.getIndex() != UTF16_CHAR_LENGTH(c) + i)
+        if(iter.getIndex() != U16_LENGTH(c) + i)
             errln((UnicodeString)"getIndex() after first32PostInc() failed");
 
         iter.setToStart();
@@ -682,7 +684,7 @@ void CharIterTest::TestIterationUChar32() {
             if(c != text.char32At(i))
                 errln("Character mismatch at position %d, iterator has %X, string has %X", i, c, text.char32At(i));
 
-            i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1;
+            i += U16_LENGTH(c);
             if(iter.getIndex() != i)
                 errln("getIndex() aftr next32PostInc() isn't working right");
             if(iter.current32() != text.char32At(i))
@@ -723,7 +725,7 @@ void CharIterTest::TestIterationUChar32() {
 
             if (c != CharacterIterator::DONE) {
                 c = iter.next32();
-                i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1;
+                i += U16_LENGTH(c);
             }
         } while (c != CharacterIterator::DONE);
         c=iter.next32();
@@ -751,7 +753,7 @@ void CharIterTest::TestIterationUChar32() {
 
             if (c != CharacterIterator::DONE) {
                 c = iter.previous32();
-                i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1;
+                i -= U16_LENGTH(c);
             }
            
         } while (c != CharacterIterator::DONE);
@@ -966,7 +968,7 @@ class SubCharIter : public CharacterIterator {
 public:
     // public default constructor, to get coverage of CharacterIterator()
     SubCharIter() : CharacterIterator() {
-        textLength=end=LENGTHOF(s);
+        textLength=end=UPRV_LENGTHOF(s);
         s[0]=0x61;      // 'a'
         s[1]=0xd900;    // U+50400
         s[2]=0xdd00;
@@ -975,7 +977,7 @@ public:
 
     // useful stuff, mostly dummy but testing coverage and subclassability
     virtual UChar nextPostInc() {
-        if(pos<LENGTHOF(s)) {
+        if(pos<UPRV_LENGTHOF(s)) {
             return s[pos++];
         } else {
             return DONE;
@@ -983,9 +985,9 @@ public:
     }
 
     virtual UChar32 next32PostInc() {
-        if(pos<LENGTHOF(s)) {
+        if(pos<UPRV_LENGTHOF(s)) {
             UChar32 c;
-            U16_NEXT(s, pos, LENGTHOF(s), c);
+            U16_NEXT(s, pos, UPRV_LENGTHOF(s), c);
             return c;
         } else {
             return DONE;
@@ -993,7 +995,7 @@ public:
     }
 
     virtual UBool hasNext() {
-        return pos<LENGTHOF(s);
+        return pos<UPRV_LENGTHOF(s);
     }
 
     virtual UChar first() {
@@ -1004,15 +1006,15 @@ public:
     virtual UChar32 first32() {
         UChar32 c;
         pos=0;
-        U16_NEXT(s, pos, LENGTHOF(s), c);
+        U16_NEXT(s, pos, UPRV_LENGTHOF(s), c);
         pos=0;
         return c;
     }
 
     virtual UChar setIndex(int32_t position) {
-        if(0<=position && position<=LENGTHOF(s)) {
+        if(0<=position && position<=UPRV_LENGTHOF(s)) {
             pos=position;
-            if(pos<LENGTHOF(s)) {
+            if(pos<UPRV_LENGTHOF(s)) {
                 return s[pos];
             }
         }
@@ -1020,11 +1022,11 @@ public:
     }
 
     virtual UChar32 setIndex32(int32_t position) {
-        if(0<=position && position<=LENGTHOF(s)) {
+        if(0<=position && position<=UPRV_LENGTHOF(s)) {
             pos=position;
-            if(pos<LENGTHOF(s)) {
+            if(pos<UPRV_LENGTHOF(s)) {
                 UChar32 c;
-                U16_GET(s, 0, pos, LENGTHOF(s), c);
+                U16_GET(s, 0, pos, UPRV_LENGTHOF(s), c);
                 return c;
             }
         }
@@ -1032,7 +1034,7 @@ public:
     }
 
     virtual UChar current() const {
-        if(pos<LENGTHOF(s)) {
+        if(pos<UPRV_LENGTHOF(s)) {
             return s[pos];
         } else {
             return DONE;
@@ -1040,9 +1042,9 @@ public:
     }
 
     virtual UChar32 current32() const {
-        if(pos<LENGTHOF(s)) {
+        if(pos<UPRV_LENGTHOF(s)) {
             UChar32 c;
-            U16_GET(s, 0, pos, LENGTHOF(s), c);
+            U16_GET(s, 0, pos, UPRV_LENGTHOF(s), c);
             return c;
         } else {
             return DONE;
@@ -1050,7 +1052,7 @@ public:
     }
 
     virtual UChar next() {
-        if(pos<LENGTHOF(s) && ++pos<LENGTHOF(s)) {
+        if(pos<UPRV_LENGTHOF(s) && ++pos<UPRV_LENGTHOF(s)) {
             return s[pos];
         } else {
             return DONE;
@@ -1058,13 +1060,13 @@ public:
     }
 
     virtual UChar32 next32() {
-        if(pos<LENGTHOF(s)) {
-            U16_FWD_1(s, pos, LENGTHOF(s));
+        if(pos<UPRV_LENGTHOF(s)) {
+            U16_FWD_1(s, pos, UPRV_LENGTHOF(s));
         }
-        if(pos<LENGTHOF(s)) {
+        if(pos<UPRV_LENGTHOF(s)) {
             UChar32 c;
             int32_t i=pos;
-            U16_NEXT(s, i, LENGTHOF(s), c);
+            U16_NEXT(s, i, UPRV_LENGTHOF(s), c);
             return c;
         } else {
             return DONE;
@@ -1076,7 +1078,7 @@ public:
     }
 
     virtual void getText(UnicodeString &result) {
-        result.setTo(s, LENGTHOF(s));
+        result.setTo(s, UPRV_LENGTHOF(s));
     }
 
     // dummy implementations of other pure virtual base class functions