]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/uidna.cpp
ICU-62123.0.1.tar.gz
[apple/icu.git] / icuSources / common / uidna.cpp
index b86ed26b673d43a795028622d39371fe1871a7a3..7cc97a93a01459d120c1d6d6f8f67e20eac571c2 100644 (file)
@@ -1,12 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
  *******************************************************************************
  *
- *   Copyright (C) 2003-2007, International Business Machines
+ *   Copyright (C) 2003-2014, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *
  *******************************************************************************
  *   file name:  uidna.cpp
- *   encoding:   US-ASCII
+ *   encoding:   UTF-8
  *   tab size:   8 (not used)
  *   indentation:4
  *
@@ -45,8 +47,6 @@ static const UChar ACE_PREFIX[] ={ 0x0078,0x006E,0x002d,0x002d } ;
 #define CAPITAL_A        0x0041
 #define CAPITAL_Z        0x005A
 
-#define DATA_FILE_NAME   "uidna"
-
 inline static UChar 
 toASCIILower(UChar ch){
     if(CAPITAL_A <= ch && ch <= CAPITAL_Z){
@@ -318,7 +318,7 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
     // Step 4: if the source is ASCII then proceed to step 8
     if(srcIsASCII){
         if(b1Len <= destCapacity){
-            uprv_memmove(dest, b1, b1Len * U_SIZEOF_UCHAR);
+            u_memmove(dest, b1, b1Len);
             reqLength = b1Len;
         }else{
             reqLength = b1Len;
@@ -364,9 +364,9 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
                 goto CLEANUP;
             }
             //Step 7: prepend the ACE prefix
-            uprv_memcpy(dest,ACE_PREFIX,ACE_PREFIX_LENGTH * U_SIZEOF_UCHAR);
+            u_memcpy(dest, ACE_PREFIX, ACE_PREFIX_LENGTH);
             //Step 6: copy the contents in b2 into dest
-            uprv_memcpy(dest+ACE_PREFIX_LENGTH, b2, b2Len * U_SIZEOF_UCHAR);
+            u_memcpy(dest+ACE_PREFIX_LENGTH, b2, b2Len);
 
         }else{
             *status = U_IDNA_ACE_PREFIX_ERROR; 
@@ -410,13 +410,12 @@ _internal_toUnicode(const UChar* src, int32_t srcLength,
 
     //initialize pointers to stack buffers
     UChar  *b1 = b1Stack, *b2 = b2Stack, *b1Prime=NULL, *b3=b3Stack;
-    int32_t b1Len, b2Len, b1PrimeLen, b3Len,
+    int32_t b1Len = 0, b2Len, b1PrimeLen, b3Len,
             b1Capacity = MAX_LABEL_BUFFER_SIZE, 
             b2Capacity = MAX_LABEL_BUFFER_SIZE,
             b3Capacity = MAX_LABEL_BUFFER_SIZE,
             reqLength=0;
 
-    b1Len = 0;
     UBool* caseFlags = NULL;
 
     UBool srcIsASCII = TRUE;
@@ -544,7 +543,7 @@ _internal_toUnicode(const UChar* src, int32_t srcLength,
         //step 8: return output of step 5
         reqLength = b2Len;
         if(b2Len <= destCapacity) {
-            uprv_memmove(dest, b2, b2Len * U_SIZEOF_UCHAR);
+            u_memmove(dest, b2, b2Len);
         }
     }
     else{
@@ -573,7 +572,7 @@ _internal_toUnicode(const UChar* src, int32_t srcLength,
         // just return the source
         //copy the source to destination
         if(srcLength <= destCapacity){
-            uprv_memmove(dest,src,srcLength * U_SIZEOF_UCHAR);
+            u_memmove(dest, src, srcLength);
         }
         reqLength = srcLength;
     }
@@ -600,7 +599,7 @@ CLEANUP:
         if(dest && srcLength <= destCapacity){
             // srcLength should have already been set earlier.
             U_ASSERT(srcLength >= 0);
-            uprv_memmove(dest,src,srcLength * U_SIZEOF_UCHAR);
+            u_memmove(dest, src, srcLength);
         }
         reqLength = srcLength;
         *status = U_ZERO_ERROR;
@@ -624,7 +623,7 @@ uidna_toASCII(const UChar* src, int32_t srcLength,
         return 0;
     }
 
-    UStringPrepProfile* nameprep = usprep_open(NULL,DATA_FILE_NAME, status);
+    UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status);
     
     if(U_FAILURE(*status)){
         return -1;
@@ -653,7 +652,7 @@ uidna_toUnicode(const UChar* src, int32_t srcLength,
         return 0;
     }  
 
-    UStringPrepProfile* nameprep = usprep_open(NULL, DATA_FILE_NAME, status);
+    UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status);
     
     if(U_FAILURE(*status)){
         return -1;
@@ -684,7 +683,7 @@ uidna_IDNToASCII(  const UChar *src, int32_t srcLength,
 
     int32_t reqLength = 0;
 
-    UStringPrepProfile* nameprep = usprep_open(NULL, DATA_FILE_NAME, status);
+    UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status);
     
     if(U_FAILURE(*status)){
         return 0;
@@ -777,7 +776,7 @@ uidna_IDNToUnicode(  const UChar* src, int32_t srcLength,
 
     int32_t reqLength = 0;
 
-    UStringPrepProfile* nameprep = usprep_open(NULL, DATA_FILE_NAME, status);
+    UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status);
     
     if(U_FAILURE(*status)){
         return 0;