ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / common / uchriter.cpp
index ae73695a8106b0c879a9025abc3ae46a8f26211d..822168f5c8e600ea58d52d94d792949c195b4319 100644 (file)
@@ -1,13 +1,18 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 ******************************************************************************
-* Copyright (C) 1998-2004, International Business Machines Corporation and   *
-* others. All Rights Reserved.                                               *
+* Copyright (C) 1998-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
 ******************************************************************************
 */
 
+#include "utypeinfo.h"  // for 'typeid' to work
+
 #include "unicode/uchriter.h"
 #include "unicode/ustring.h"
-#include "uhash.h"
+#include "unicode/utf16.h"
+#include "ustr_imp.h"
 
 U_NAMESPACE_BEGIN
 
@@ -20,14 +25,14 @@ UCharCharacterIterator::UCharCharacterIterator()
     // never default construct!
 }
 
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
                                                int32_t length)
   : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0),
   text(textPtr)
 {
 }
 
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
                                                int32_t length,
                                                int32_t position)
   : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0, position),
@@ -35,7 +40,7 @@ UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
 {
 }
 
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
                                                int32_t length,
                                                int32_t textBegin,
                                                int32_t textEnd,
@@ -66,8 +71,7 @@ UCharCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
     if (this == &that) {
         return TRUE;
     }
-    
-    if (getDynamicClassID() != that.getDynamicClassID()) {
+    if (typeid(*this) != typeid(that)) {
         return FALSE;
     }
 
@@ -82,7 +86,7 @@ UCharCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
 
 int32_t
 UCharCharacterIterator::hashCode() const {
-    return uhash_hashUCharsN(text, textLength) ^ pos ^ begin ^ end;
+    return ustr_hashUCharsN(text, textLength) ^ pos ^ begin ^ end;
 }
 
 CharacterIterator*
@@ -190,7 +194,7 @@ UCharCharacterIterator::first32() {
     if(pos < end) {
         int32_t i = pos;
         UChar32 c;
-        UTF_NEXT_CHAR(text, i, end, c);
+        U16_NEXT(text, i, end, c);
         return c;
     } else {
         return DONE;
@@ -202,7 +206,7 @@ UCharCharacterIterator::first32PostInc() {
     pos = begin;
     if(pos < end) {
         UChar32 c;
-        UTF_NEXT_CHAR(text, pos, end, c);
+        U16_NEXT(text, pos, end, c);
         return c;
     } else {
         return DONE;
@@ -214,7 +218,7 @@ UCharCharacterIterator::last32() {
     pos = end;
     if(pos > begin) {
         UChar32 c;
-        UTF_PREV_CHAR(text, begin, pos, c);
+        U16_PREV(text, begin, pos, c);
         return c;
     } else {
         return DONE;
@@ -229,10 +233,10 @@ UCharCharacterIterator::setIndex32(int32_t position) {
         position = end;
     }
     if(position < end) {
-        UTF_SET_CHAR_START(text, begin, position);
+        U16_SET_CP_START(text, begin, position);
         int32_t i = this->pos = position;
         UChar32 c;
-        UTF_NEXT_CHAR(text, i, end, c);
+        U16_NEXT(text, i, end, c);
         return c;
     } else {
         this->pos = position;
@@ -244,7 +248,7 @@ UChar32
 UCharCharacterIterator::current32() const {
     if (pos >= begin && pos < end) {
         UChar32 c;
-        UTF_GET_CHAR(text, begin, pos, end, c);
+        U16_GET(text, begin, pos, end, c);
         return c;
     } else {
         return DONE;
@@ -254,11 +258,11 @@ UCharCharacterIterator::current32() const {
 UChar32
 UCharCharacterIterator::next32() {
     if (pos < end) {
-        UTF_FWD_1(text, pos, end);
+        U16_FWD_1(text, pos, end);
         if(pos < end) {
             int32_t i = pos;
             UChar32 c;
-            UTF_NEXT_CHAR(text, i, end, c);
+            U16_NEXT(text, i, end, c);
             return c;
         }
     }
@@ -271,7 +275,7 @@ UChar32
 UCharCharacterIterator::next32PostInc() {
     if (pos < end) {
         UChar32 c;
-        UTF_NEXT_CHAR(text, pos, end, c);
+        U16_NEXT(text, pos, end, c);
         return c;
     } else {
         return DONE;
@@ -282,7 +286,7 @@ UChar32
 UCharCharacterIterator::previous32() {
     if (pos > begin) {
         UChar32 c;
-        UTF_PREV_CHAR(text, begin, pos, c);
+        U16_PREV(text, begin, pos, c);
         return c;
     } else {
         return DONE;
@@ -322,20 +326,20 @@ UCharCharacterIterator::move32(int32_t delta, CharacterIterator::EOrigin origin)
     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:
@@ -345,7 +349,7 @@ UCharCharacterIterator::move32(int32_t delta, CharacterIterator::EOrigin origin)
     return pos;
 }
 
-void UCharCharacterIterator::setText(const UChar* newText,
+void UCharCharacterIterator::setText(ConstChar16Ptr newText,
                                      int32_t      newTextLength) {
     text = newText;
     if(newText == 0 || newTextLength < 0) {