]> granicus.if.org Git - icu/commitdiff
ICU-12634 Remove ResourceTableSink and ures_getAllTableItems().
authorFelipe Balbontín <fabalbon@google.com>
Wed, 7 Sep 2016 19:22:41 +0000 (19:22 +0000)
committerFelipe Balbontín <fabalbon@google.com>
Wed, 7 Sep 2016 19:22:41 +0000 (19:22 +0000)
X-SVN-Rev: 39155

icu4c/source/common/resource.cpp
icu4c/source/common/resource.h
icu4c/source/common/unicode/urename.h
icu4c/source/common/uresbund.cpp
icu4c/source/common/uresdata.cpp
icu4c/source/common/uresdata.h
icu4c/source/common/uresimp.h

index d0add241ed9090402e3ea54e6b767d84f6c200df..62b3aa46a5c0831a098e26eb2e7aa5b8fbade320 100644 (file)
 
 #include "resource.h"
 
-#include "unicode/utypes.h"
-#include "unicode/uobject.h"
-#include "unicode/ures.h"
-
 U_NAMESPACE_BEGIN
 
 ResourceValue::~ResourceValue() {}
 
 ResourceSink::~ResourceSink() {}
 
-ResourceTableSink::~ResourceTableSink() {}
-
-void ResourceTableSink::put(
-        const char * /*key*/, const ResourceValue & /*value*/, UErrorCode & /*errorCode*/) {}
-
-void ResourceTableSink::putNoFallback(const char * /*key*/, UErrorCode & /*errorCode*/) {}
-
-ResourceTableSink *ResourceTableSink::getOrCreateTableSink(
-        const char * /*key*/, UErrorCode & /*errorCode*/) {
-    return NULL;
-}
-
 U_NAMESPACE_END
index 5db59ad3cf17e852ad23b1ce42dc1d86ac8f857a..43c3309b5e9917484e3d590467f35d4ec73ae8be 100644 (file)
@@ -33,7 +33,6 @@ struct ResourceData;
 
 U_NAMESPACE_BEGIN
 
-class ResourceTableSink;
 class ResourceValue;
 
 // Note: In C++, we use const char * pointers for keys,
@@ -275,55 +274,6 @@ private:
     ResourceSink &operator=(const ResourceSink &);  // no assignment operator
 };
 
-/**
- * Sink for ICU resource table contents.
- * The base class does nothing.
- *
- * Nested arrays and tables are stored as nested sinks,
- * never put() as ResourceValue items.
- */
-class U_COMMON_API ResourceTableSink : public UObject {
-public:
-    ResourceTableSink() {}
-    virtual ~ResourceTableSink();
-
-    /**
-     * Adds a key-value pair from a resource table.
-     *
-     * @param key resource key string
-     * @param value resource value
-     */
-    virtual void put(const char *key, const ResourceValue &value, UErrorCode &errorCode);
-
-    /**
-     * Adds a no-fallback/no-inheritance marker for this key.
-     * Used for CLDR no-fallback data values of (three empty-set symbols)=={2205, 2205, 2205}
-     * when enumerating tables with fallback from the specific resource bundle to root.
-     *
-     * The default implementation does nothing.
-     *
-     * @param key to be removed
-     */
-    virtual void putNoFallback(const char *key, UErrorCode &errorCode);
-
-    /**
-     * Returns a nested resource table for the key as another sink.
-     * Creates the sink if none exists for the key.
-     * Returns NULL if nested tables are not supported.
-     * The default implementation always returns NULL.
-     *
-     * This sink (not the caller) owns the nested sink.
-     *
-     * @param key resource key string
-     * @return nested-table sink, or NULL
-     */
-    virtual ResourceTableSink *getOrCreateTableSink(const char *key, UErrorCode &errorCode);
-
-private:
-    ResourceTableSink(const ResourceTableSink &);  // no copy constructor
-    ResourceTableSink &operator=(const ResourceTableSink &);  // no assignment operator
-};
-
 U_NAMESPACE_END
 
 #endif
index d46a0923dde68336b76b1e5ab5ee66c42e3fb954..5294ff545e4ad16b287819667395c4e5e4d0566b 100644 (file)
 #define ures_findResource U_ICU_ENTRY_POINT_RENAME(ures_findResource)
 #define ures_findSubResource U_ICU_ENTRY_POINT_RENAME(ures_findSubResource)
 #define ures_getAllItemsWithFallback U_ICU_ENTRY_POINT_RENAME(ures_getAllItemsWithFallback)
-#define ures_getAllTableItems U_ICU_ENTRY_POINT_RENAME(ures_getAllTableItems)
-#define ures_getAllTableItemsWithFallback U_ICU_ENTRY_POINT_RENAME(ures_getAllTableItemsWithFallback)
 #define ures_getBinary U_ICU_ENTRY_POINT_RENAME(ures_getBinary)
 #define ures_getByIndex U_ICU_ENTRY_POINT_RENAME(ures_getByIndex)
 #define ures_getByKey U_ICU_ENTRY_POINT_RENAME(ures_getByKey)
index 0f19599e953e92593c2ca16e544f956dc1658370..c49e1e548683307134021e691e3c7d74c763d73c 100644 (file)
@@ -1889,8 +1889,7 @@ namespace {
 
 void getAllItemsWithFallback(
         const UResourceBundle *bundle, ResourceDataValue &value,
-        ResourceSink *sink,
-        ResourceTableSink *tableSink,
+        ResourceSink &sink,
         UErrorCode &errorCode) {
     if (U_FAILURE(errorCode)) { return; }
     // We recursively enumerate child-first,
@@ -1906,18 +1905,8 @@ void getAllItemsWithFallback(
     value.pResData = &bundle->fResData;
     UResourceDataEntry *parentEntry = bundle->fData->fParent;
     UBool hasParent = parentEntry != NULL && U_SUCCESS(parentEntry->fBogus);
-    UResType expectedType;
-    if (sink != NULL) {
-        expectedType = URES_NONE;
-        value.setResource(bundle->fRes);
-        sink->put(bundle->fKey, value, !hasParent, errorCode);
-    } else {
-        expectedType = URES_TABLE;
-        if (ures_getType(bundle) == expectedType) {
-            //tableSink != NULL
-            ures_getAllTableItems(&bundle->fResData, bundle->fRes, value, *tableSink, errorCode);
-        }
-    }
+    value.setResource(bundle->fRes);
+    sink.put(bundle->fKey, value, !hasParent, errorCode);
     if (hasParent) {
         // We might try to query the sink whether
         // any fallback from the parent bundle is still possible.
@@ -1951,19 +1940,19 @@ void getAllItemsWithFallback(
             rb = ures_getByKeyWithFallback(&parentBundle, bundle->fResPath,
                                            &containerBundle, &pathErrorCode);
         }
-        if (U_SUCCESS(pathErrorCode) && (expectedType == URES_NONE || ures_getType(rb) == expectedType)) {
-            getAllItemsWithFallback(rb, value, sink, tableSink, errorCode);
+        if (U_SUCCESS(pathErrorCode)) {
+            getAllItemsWithFallback(rb, value, sink, errorCode);
         }
         ures_close(&containerBundle);
         ures_close(&parentBundle);
     }
 }
 
-void getAllItemsWithFallback(
-        const UResourceBundle *bundle, const char *path,
-        ResourceSink *sink,
-        ResourceTableSink *tableSink,
-        UErrorCode &errorCode) {
+}  // namespace
+
+U_CAPI void U_EXPORT2
+ures_getAllItemsWithFallback(const UResourceBundle *bundle, const char *path,
+                             icu::ResourceSink &sink, UErrorCode &errorCode) {
     if (U_FAILURE(errorCode)) { return; }
     if (path == NULL) {
         errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -1982,34 +1971,12 @@ void getAllItemsWithFallback(
             return;
         }
     }
-    if (sink == NULL) {
-        UResType expectedType = URES_TABLE;
-        if (ures_getType(rb) != expectedType) {
-            errorCode = U_RESOURCE_TYPE_MISMATCH;
-            ures_close(&stackBundle);
-            return;
-        }
-    }
     // Get all table items with fallback.
     ResourceDataValue value;
-    getAllItemsWithFallback(rb, value, sink, tableSink, errorCode);
+    getAllItemsWithFallback(rb, value, sink, errorCode);
     ures_close(&stackBundle);
 }
 
-}  // namespace
-
-U_CAPI void U_EXPORT2
-ures_getAllItemsWithFallback(const UResourceBundle *bundle, const char *path,
-                             icu::ResourceSink &sink, UErrorCode &errorCode) {
-    getAllItemsWithFallback(bundle, path, &sink, NULL, errorCode);
-}
-
-U_CAPI void U_EXPORT2
-ures_getAllTableItemsWithFallback(const UResourceBundle *bundle, const char *path,
-                                  ResourceTableSink &sink, UErrorCode &errorCode) {
-    getAllItemsWithFallback(bundle, path, NULL, &sink, errorCode);
-}
-
 U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, const char* inKey, UResourceBundle *fillIn, UErrorCode *status) {
     Resource res = RES_BOGUS;
     UResourceDataEntry *realData = NULL;
index 51d835597cc8aceb403fa36273b113e6f6b2cce4..9a1ed11d60f312186d9a3942f70a880334e5be51 100644 (file)
@@ -811,85 +811,6 @@ res_getResource(const ResourceData *pResData, const char *key) {
     return res_getTableItemByKey(pResData, pResData->rootRes, &idx, &realKey);
 }
 
-// TODO: Ported from Java, but enumerating at this low level may prevent us
-// from doing necessary things, like resolving aliases,
-// which need access to higher-level UResourceBundle code.
-// Consider porting the low-level Container/Array/Table classes from Java,
-// with getters for keys and values,
-// and doing the enumeration in the higher-level code on top of those accessors.
-U_CFUNC void
-ures_getAllTableItems(const ResourceData *pResData, Resource table,
-                      icu::ResourceDataValue &value, icu::ResourceTableSink &sink,
-                      UErrorCode &errorCode) {
-    if(U_FAILURE(errorCode)) { return; }
-    const uint16_t *keys16 = NULL;
-    const int32_t *keys32 = NULL;
-    const uint16_t *items16 = NULL;
-    const Resource *items32 = NULL;
-    uint32_t offset = RES_GET_OFFSET(table);
-    int32_t length = 0;
-    switch(RES_GET_TYPE(table)) {
-    case URES_TABLE:
-        if (offset != 0) {  // empty if offset==0
-            keys16 = (const uint16_t *)(pResData->pRoot+offset);
-            length = *keys16++;
-            items32 = (const Resource *)(keys16+length+(~length&1));
-        }
-        break;
-    case URES_TABLE16:
-        keys16 = pResData->p16BitUnits+offset;
-        length = *keys16++;
-        items16 = keys16 + length;
-        break;
-    case URES_TABLE32:
-        if (offset != 0) {  // empty if offset==0
-            keys32 = pResData->pRoot+offset;
-            length = *keys32++;
-            items32 = (const Resource *)keys32 + length;
-        }
-        break;
-    default:
-        errorCode = U_RESOURCE_TYPE_MISMATCH;
-        return;
-    }
-    if(U_FAILURE(errorCode)) { return; }
-
-    for (int32_t i = 0; i < length; ++i) {
-        const char *key;
-        if (keys16 != NULL) {
-            key=RES_GET_KEY16(pResData, keys16[i]);
-        } else {
-            key=RES_GET_KEY32(pResData, keys32[i]);
-        }
-        Resource res;
-        if (items16 != NULL) {
-            res = makeResourceFrom16(pResData, items16[i]);
-        } else {
-            res = items32[i];
-        }
-        int32_t type = RES_GET_TYPE(res);
-        if (URES_IS_ARRAY(type)) {
-            // ICU ticket #12634: This original version of the enumeration code
-            // is going away. getOrCreateArraySink(key) was unused and has been removed.
-        } else if (URES_IS_TABLE(type)) {
-            icu::ResourceTableSink *subSink = sink.getOrCreateTableSink(key, errorCode);
-            if (subSink != NULL) {
-                ures_getAllTableItems(pResData, res, value, *subSink, errorCode);
-            }
-        /* TODO: settle on how to deal with aliases, port to Java
-        } else if (type == URES_ALIAS) {
-            // aliases not handled in resource enumeration
-            errorCode = U_UNSUPPORTED_ERROR;
-            return; */
-        } else if (isNoInheritanceMarker(pResData, res)) {
-            sink.putNoFallback(key, errorCode);
-        } else {
-            value.setResource(res);
-            sink.put(key, value, errorCode);
-        }
-        if(U_FAILURE(errorCode)) { return; }
-    }
-}
 
 UBool icu::ResourceTable::getKeyAndValue(int32_t i,
                                          const char *&key, icu::ResourceValue &value) const {
index 77b3c3d5de3ff542d5ad89c23e8955a358f08510..ae7d9a817d2b2feb4bcdd1e52c215db284a179d3 100644 (file)
@@ -505,15 +505,6 @@ private:
 
 U_NAMESPACE_END
 
-/**
- * @param value will be set during enumeration; input contents is ignored
- * @param sink receives all table item key-value pairs
- */
-U_CFUNC void
-ures_getAllTableItems(const ResourceData *pResData, Resource table,
-                      icu::ResourceDataValue &value, icu::ResourceTableSink &sink,
-                      UErrorCode &errorCode);
-
 #endif  /* __cplusplus */
 
 /**
index f2b26bd4a41b77b3ab797cdb13bb56722e0a83f9..5645ee92165c001999d56d1099db63e0833c4c26 100644 (file)
@@ -230,10 +230,6 @@ U_CAPI void U_EXPORT2
 ures_getAllItemsWithFallback(const UResourceBundle *bundle, const char *path,
                              icu::ResourceSink &sink, UErrorCode &errorCode);
 
-U_CAPI void U_EXPORT2
-ures_getAllTableItemsWithFallback(const UResourceBundle *bundle, const char *path,
-                                  icu::ResourceTableSink &sink, UErrorCode &errorCode);
-
 #endif  /* __cplusplus */
 
 /**