]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/idnaref.cpp
ICU-531.48.tar.gz
[apple/icu.git] / icuSources / test / intltest / idnaref.cpp
index eabe1f56d3a1206cd6d314c916a311903528b9d6..33f0918f24fbf789b2cdfd83f1db6cafaf486886 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
  *
- *   Copyright (C) 2003-2007, International Business Machines
+ *   Copyright (C) 2003-2011, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *
  *******************************************************************************
@@ -285,31 +285,33 @@ idnaref_toASCII(const UChar* src, int32_t srcLength,
         }
         b1[b1Len++] = src[j];
     }
-    // step 2
-    NamePrepTransform* prep = TestIDNA::getInstance(*status);
 
+    NamePrepTransform* prep = TestIDNA::getInstance(*status);
     if(U_FAILURE(*status)){
         goto CLEANUP;
     }
 
-    b1Len = prep->process(src,srcLength,b1, b1Capacity,allowUnassigned,parseError,*status);
+    // step 2 is performed only if the source contains non ASCII
+    if (!srcIsASCII) {
+        b1Len = prep->process(src,srcLength,b1, b1Capacity,allowUnassigned,parseError,*status);
 
-    if(*status == U_BUFFER_OVERFLOW_ERROR){
-        // redo processing of string
-        /* we do not have enough room so grow the buffer*/
-        b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR);
-        if(b1==NULL){
-            *status = U_MEMORY_ALLOCATION_ERROR;
-            goto CLEANUP;
-        }
+        if(*status == U_BUFFER_OVERFLOW_ERROR){
+            // redo processing of string
+            /* we do not have enough room so grow the buffer*/
+            b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR);
+            if(b1==NULL){
+                *status = U_MEMORY_ALLOCATION_ERROR;
+                goto CLEANUP;
+            }
 
-        *status = U_ZERO_ERROR; // reset error
+            *status = U_ZERO_ERROR; // reset error
 
-        b1Len = prep->process(src,srcLength,b1, b1Len,allowUnassigned, parseError, *status);
-    }
-    // error bail out
-    if(U_FAILURE(*status)){
-        goto CLEANUP;
+            b1Len = prep->process(src,srcLength,b1, b1Len,allowUnassigned, parseError, *status);
+        }
+        // error bail out
+        if(U_FAILURE(*status)){
+            goto CLEANUP;
+        }
     }
 
     if(b1Len == 0){