]> granicus.if.org Git - icu/commitdiff
ICU-10282 deprecate bad API RuleBasedCollator::cloneRuleData(), call cloneBinary()
authorMarkus Scherer <markus.icu@gmail.com>
Fri, 13 Sep 2013 19:25:01 +0000 (19:25 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Fri, 13 Sep 2013 19:25:01 +0000 (19:25 +0000)
X-SVN-Rev: 34314

icu4c/source/i18n/tblcoll.cpp
icu4c/source/i18n/ucol.cpp
icu4c/source/i18n/ucol_imp.h
icu4c/source/i18n/unicode/tblcoll.h
icu4c/source/tools/genrb/parse.cpp

index cbe0394930c723d5c97b026a5dcb74b3c542c160..75458542ff81fba95dd43e47efd0b174d6499a0c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  ******************************************************************************
- * Copyright (C) 1996-2012, International Business Machines Corporation and
+ * Copyright (C) 1996-2013, International Business Machines Corporation and
  * others. All Rights Reserved.
  ******************************************************************************
  */
@@ -456,7 +456,23 @@ int32_t RuleBasedCollator::getMaxExpansion(int32_t order) const
 uint8_t* RuleBasedCollator::cloneRuleData(int32_t &length,
                                               UErrorCode &status)
 {
-    return ucol_cloneRuleData(ucollator, &length, &status);
+    if (U_FAILURE(status)) { return NULL; }
+    LocalMemory<uint8_t> buffer((uint8_t *)uprv_malloc(20000));
+    if (buffer.isNull()) {
+        status = U_MEMORY_ALLOCATION_ERROR;
+        return NULL;
+    }
+    length = cloneBinary(buffer.getAlias(), 20000, status);
+    if (status == U_BUFFER_OVERFLOW_ERROR) {
+        if (buffer.allocateInsteadAndCopy(length, 0) == NULL) {
+            status = U_MEMORY_ALLOCATION_ERROR;
+            return NULL;
+        }
+        status = U_ZERO_ERROR;
+        length = cloneBinary(buffer.getAlias(), length, status);
+    }
+    if (U_FAILURE(status)) { return NULL; }
+    return buffer.orphan();
 }
 
 
index 6a5a820becca1a47720dc394aac9f2ccdac88233..54fe8a3d39086e5b0820908563266e842b8c6921 100644 (file)
@@ -764,68 +764,6 @@ ucol_close(UCollator *coll)
     UTRACE_EXIT();
 }
 
-/* This one is currently used by genrb & tests. After constructing from rules (tailoring),*/
-/* you should be able to get the binary chunk to write out...  Doesn't look very full now */
-U_CFUNC uint8_t* U_EXPORT2
-ucol_cloneRuleData(const UCollator *coll, int32_t *length, UErrorCode *status)
-{
-    uint8_t *result = NULL;
-    if(U_FAILURE(*status)) {
-        return NULL;
-    }
-    if(coll->hasRealData == TRUE) {
-        *length = coll->image->size;
-        result = (uint8_t *)uprv_malloc(*length);
-        /* test for NULL */
-        if (result == NULL) {
-            *status = U_MEMORY_ALLOCATION_ERROR;
-            return NULL;
-        }
-        uprv_memcpy(result, coll->image, *length);
-    } else {
-        *length = (int32_t)(paddedsize(sizeof(UCATableHeader))+paddedsize(sizeof(UColOptionSet)));
-        result = (uint8_t *)uprv_malloc(*length);
-        /* test for NULL */
-        if (result == NULL) {
-            *status = U_MEMORY_ALLOCATION_ERROR;
-            return NULL;
-        }
-
-        /* build the UCATableHeader with minimal entries */
-        /* do not copy the header from the UCA file because its values are wrong! */
-        /* uprv_memcpy(result, UCA->image, sizeof(UCATableHeader)); */
-
-        /* reset everything */
-        uprv_memset(result, 0, *length);
-
-        /* set the tailoring-specific values */
-        UCATableHeader *myData = (UCATableHeader *)result;
-        myData->size = *length;
-
-        /* offset for the options, the only part of the data that is present after the header */
-        myData->options = sizeof(UCATableHeader);
-
-        /* need to always set the expansion value for an upper bound of the options */
-        myData->expansion = myData->options + sizeof(UColOptionSet);
-
-        myData->magic = UCOL_HEADER_MAGIC;
-        myData->isBigEndian = U_IS_BIG_ENDIAN;
-        myData->charSetFamily = U_CHARSET_FAMILY;
-
-        /* copy UCA's version; genrb will override all but the builder version with tailoring data */
-        uprv_memcpy(myData->version, coll->image->version, sizeof(UVersionInfo));
-
-        uprv_memcpy(myData->UCAVersion, coll->image->UCAVersion, sizeof(UVersionInfo));
-        uprv_memcpy(myData->UCDVersion, coll->image->UCDVersion, sizeof(UVersionInfo));
-        uprv_memcpy(myData->formatVersion, coll->image->formatVersion, sizeof(UVersionInfo));
-        myData->jamoSpecial = coll->image->jamoSpecial;
-
-        /* copy the collator options */
-        uprv_memcpy(result+paddedsize(sizeof(UCATableHeader)), coll->options, sizeof(UColOptionSet));
-    }
-    return result;
-}
-
 void ucol_setOptionsFromHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status) {
     if(U_FAILURE(*status)) {
         return;
index 301188accf98b5ca2800cc7c3b1332e62b52c963..deaa2dbdb0ea894e84d6e7b968865462224201ec 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 1998-2012, International Business Machines
+*   Copyright (C) 1998-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -578,18 +578,6 @@ SortKeyGenerator(const    UCollator    *coll,
 
 #endif
 
-/**
- * Makes a copy of the Collator's rule data. The format is
- * that of .col files.
- *
- * @param length returns the length of the data, in bytes.
- * @param status the error status
- * @return memory, owned by the caller, of size 'length' bytes.
- * @internal INTERNAL USE ONLY
- */
-U_CFUNC uint8_t* U_EXPORT2 
-ucol_cloneRuleData(const UCollator *coll, int32_t *length, UErrorCode *status);
-
 /**
  * Used to set requested and valid locales on a collator returned by the collator
  * service.
index 04fd248084a94cdf668288bc3537c0e99f7c414f..947ac65d59df75708836c2b1c55f5602edb00a6d 100644 (file)
@@ -439,16 +439,19 @@ public:
      */
     static UClassID U_EXPORT2 getStaticClassID(void);
 
+#ifndef U_HIDE_DEPRECATED_API 
     /**
-     * Returns the binary format of the class's rules. The format is that of
-     * .col files.
+     * Do not use this method: The caller and the ICU library might use different heaps.
+     * Use cloneBinary() instead which writes to caller-provided memory.
+     *
+     * Returns a binary format of this collator.
      * @param length Returns the length of the data, in bytes
      * @param status the error code status.
      * @return memory, owned by the caller, of size 'length' bytes.
-     * @stable ICU 2.2
+     * @deprecated ICU 52. Use cloneBinary() instead.
      */
     uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
-
+#endif  /* U_HIDE_DEPRECATED_API */
 
     /** Creates a binary image of a collator. This binary image can be stored and 
     *  later used to instantiate a collator using ucol_openBinary.
index 5546411581eb1ca6accf4e216a7b0be4bca5b0f2..ab7bcca23d47de084293557c9fca255d4e60fd6e 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 1998-2012, International Business Machines
+*   Copyright (C) 1998-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -937,7 +937,6 @@ addCollation(ParseState* state, struct SResource  *result, uint32_t startline, U
                     data = (uint8_t *)uprv_malloc(len);
                     intStatus = U_ZERO_ERROR;
                     len = ucol_cloneBinary(coll, data, len, &intStatus);
-                    /*data = ucol_cloneRuleData(coll, &len, &intStatus);*/
 
                     /* tailoring rules version */
                     /* This is wrong! */