From b17650f34a4f26ae74cae60ccc8f96e047636a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Balbont=C3=ADn?= Date: Tue, 19 Jul 2016 18:37:37 +0000 Subject: [PATCH] ICU-12634 Remove ResourceArraySink and ResourceTableSink.enter(), leave() and getOrCreateArraySink(). X-SVN-Rev: 38983 --- icu4c/source/common/resource.cpp | 29 -------- icu4c/source/common/resource.h | 98 --------------------------- icu4c/source/common/unicode/urename.h | 2 - icu4c/source/common/uresbund.cpp | 29 +++----- icu4c/source/common/uresdata.cpp | 67 +----------------- icu4c/source/common/uresdata.h | 9 --- icu4c/source/common/uresimp.h | 4 -- 7 files changed, 12 insertions(+), 226 deletions(-) diff --git a/icu4c/source/common/resource.cpp b/icu4c/source/common/resource.cpp index c0a993c0c5a..d0add241ed9 100644 --- a/icu4c/source/common/resource.cpp +++ b/icu4c/source/common/resource.cpp @@ -23,45 +23,16 @@ ResourceValue::~ResourceValue() {} ResourceSink::~ResourceSink() {} -ResourceArraySink::~ResourceArraySink() {} - -void ResourceArraySink::enter(int32_t /*size*/, UErrorCode & /*errorCode*/) {} - -void ResourceArraySink::put( - int32_t /*index*/, const ResourceValue & /*value*/, UErrorCode & /*errorCode*/) {} - -ResourceArraySink *ResourceArraySink::getOrCreateArraySink( - int32_t /*index*/, UErrorCode & /*errorCode*/) { - return NULL; -} - -ResourceTableSink *ResourceArraySink::getOrCreateTableSink( - int32_t /*index*/, UErrorCode & /*errorCode*/) { - return NULL; -} - -void ResourceArraySink::leave(UErrorCode & /*errorCode*/) {} - - ResourceTableSink::~ResourceTableSink() {} -void ResourceTableSink::enter(int32_t /*size*/, UErrorCode & /*errorCode*/) {} - void ResourceTableSink::put( const char * /*key*/, const ResourceValue & /*value*/, UErrorCode & /*errorCode*/) {} void ResourceTableSink::putNoFallback(const char * /*key*/, UErrorCode & /*errorCode*/) {} -ResourceArraySink *ResourceTableSink::getOrCreateArraySink( - const char * /*key*/, UErrorCode & /*errorCode*/) { - return NULL; -} - ResourceTableSink *ResourceTableSink::getOrCreateTableSink( const char * /*key*/, UErrorCode & /*errorCode*/) { return NULL; } -void ResourceTableSink::leave(UErrorCode & /*errorCode*/) {} - U_NAMESPACE_END diff --git a/icu4c/source/common/resource.h b/icu4c/source/common/resource.h index 75d0fbc3784..5db59ad3cf1 100644 --- a/icu4c/source/common/resource.h +++ b/icu4c/source/common/resource.h @@ -275,74 +275,6 @@ private: ResourceSink &operator=(const ResourceSink &); // no assignment operator }; -/** - * Sink for ICU resource array contents. - * The base class does nothing. - * - * Nested arrays and tables are stored as nested sinks, - * never put() as ResourceValue items. - */ -class U_COMMON_API ResourceArraySink : public UObject { -public: - ResourceArraySink() {} - virtual ~ResourceArraySink(); - - /** - * "Enters" the array. - * Called just before enumerating the array's resource items. - * The size can be used to allocate storage for the items. - * It may differ between child and parent bundles. - * - * @param size number of array items - */ - virtual void enter(int32_t size, UErrorCode &errorCode); - - /** - * Adds a value from a resource array. - * - * @param index of the resource array item - * @param value resource value - */ - virtual void put(int32_t index, const ResourceValue &value, UErrorCode &errorCode); - - /** - * Returns a nested resource array at the array index as another sink. - * Creates the sink if none exists for the key. - * Returns NULL if nested arrays are not supported. - * The default implementation always returns NULL. - * - * This sink (not the caller) owns the nested sink. - * - * @param index of the resource array item - * @return nested-array sink, or NULL - */ - virtual ResourceArraySink *getOrCreateArraySink(int32_t index, UErrorCode &errorCode); - - /** - * Returns a nested resource table at the array index 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 index of the resource array item - * @return nested-table sink, or NULL - */ - virtual ResourceTableSink *getOrCreateTableSink(int32_t index, UErrorCode &errorCode); - - /** - * "Leaves" the array. - * Indicates that all of the resources and sub-resources of the current array - * have been enumerated. - */ - virtual void leave(UErrorCode &errorCode); - -private: - ResourceArraySink(const ResourceArraySink &); // no copy constructor - ResourceArraySink &operator=(const ResourceArraySink &); // no assignment operator -}; - /** * Sink for ICU resource table contents. * The base class does nothing. @@ -355,16 +287,6 @@ public: ResourceTableSink() {} virtual ~ResourceTableSink(); - /** - * "Enters" the table. - * Called just before enumerating the table's resource items. - * The size can be used to allocate storage for the items. - * It usually differs between child and parent bundles. - * - * @param size number of table items - */ - virtual void enter(int32_t size, UErrorCode &errorCode); - /** * Adds a key-value pair from a resource table. * @@ -384,19 +306,6 @@ public: */ virtual void putNoFallback(const char *key, UErrorCode &errorCode); - /** - * Returns a nested resource array for the key as another sink. - * Creates the sink if none exists for the key. - * Returns NULL if nested arrays 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-array sink, or NULL - */ - virtual ResourceArraySink *getOrCreateArraySink(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. @@ -410,13 +319,6 @@ public: */ virtual ResourceTableSink *getOrCreateTableSink(const char *key, UErrorCode &errorCode); - /** - * "Leaves" the table. - * Indicates that all of the resources and sub-resources of the current table - * have been enumerated. - */ - virtual void leave(UErrorCode &errorCode); - private: ResourceTableSink(const ResourceTableSink &); // no copy constructor ResourceTableSink &operator=(const ResourceTableSink &); // no assignment operator diff --git a/icu4c/source/common/unicode/urename.h b/icu4c/source/common/unicode/urename.h index c02730eac3e..d46a0923dde 100644 --- a/icu4c/source/common/unicode/urename.h +++ b/icu4c/source/common/unicode/urename.h @@ -1460,8 +1460,6 @@ #define ures_countArrayItems U_ICU_ENTRY_POINT_RENAME(ures_countArrayItems) #define ures_findResource U_ICU_ENTRY_POINT_RENAME(ures_findResource) #define ures_findSubResource U_ICU_ENTRY_POINT_RENAME(ures_findSubResource) -#define ures_getAllArrayItems U_ICU_ENTRY_POINT_RENAME(ures_getAllArrayItems) -#define ures_getAllArrayItemsWithFallback U_ICU_ENTRY_POINT_RENAME(ures_getAllArrayItemsWithFallback) #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) diff --git a/icu4c/source/common/uresbund.cpp b/icu4c/source/common/uresbund.cpp index 2a4eaf655ee..0f19599e953 100644 --- a/icu4c/source/common/uresbund.cpp +++ b/icu4c/source/common/uresbund.cpp @@ -1890,7 +1890,7 @@ namespace { void getAllItemsWithFallback( const UResourceBundle *bundle, ResourceDataValue &value, ResourceSink *sink, - ResourceArraySink *arraySink, ResourceTableSink *tableSink, + ResourceTableSink *tableSink, UErrorCode &errorCode) { if (U_FAILURE(errorCode)) { return; } // We recursively enumerate child-first, @@ -1912,13 +1912,10 @@ void getAllItemsWithFallback( value.setResource(bundle->fRes); sink->put(bundle->fKey, value, !hasParent, errorCode); } else { - expectedType = arraySink != NULL ? URES_ARRAY : URES_TABLE; + expectedType = URES_TABLE; if (ures_getType(bundle) == expectedType) { - if (arraySink != NULL) { - ures_getAllArrayItems(&bundle->fResData, bundle->fRes, value, *arraySink, errorCode); - } else /* tableSink != NULL */ { - ures_getAllTableItems(&bundle->fResData, bundle->fRes, value, *tableSink, errorCode); - } + //tableSink != NULL + ures_getAllTableItems(&bundle->fResData, bundle->fRes, value, *tableSink, errorCode); } } if (hasParent) { @@ -1955,7 +1952,7 @@ void getAllItemsWithFallback( &containerBundle, &pathErrorCode); } if (U_SUCCESS(pathErrorCode) && (expectedType == URES_NONE || ures_getType(rb) == expectedType)) { - getAllItemsWithFallback(rb, value, sink, arraySink, tableSink, errorCode); + getAllItemsWithFallback(rb, value, sink, tableSink, errorCode); } ures_close(&containerBundle); ures_close(&parentBundle); @@ -1965,7 +1962,7 @@ void getAllItemsWithFallback( void getAllItemsWithFallback( const UResourceBundle *bundle, const char *path, ResourceSink *sink, - ResourceArraySink *arraySink, ResourceTableSink *tableSink, + ResourceTableSink *tableSink, UErrorCode &errorCode) { if (U_FAILURE(errorCode)) { return; } if (path == NULL) { @@ -1986,7 +1983,7 @@ void getAllItemsWithFallback( } } if (sink == NULL) { - UResType expectedType = arraySink != NULL ? URES_ARRAY : URES_TABLE; + UResType expectedType = URES_TABLE; if (ures_getType(rb) != expectedType) { errorCode = U_RESOURCE_TYPE_MISMATCH; ures_close(&stackBundle); @@ -1995,7 +1992,7 @@ void getAllItemsWithFallback( } // Get all table items with fallback. ResourceDataValue value; - getAllItemsWithFallback(rb, value, sink, arraySink, tableSink, errorCode); + getAllItemsWithFallback(rb, value, sink, tableSink, errorCode); ures_close(&stackBundle); } @@ -2004,19 +2001,13 @@ void getAllItemsWithFallback( U_CAPI void U_EXPORT2 ures_getAllItemsWithFallback(const UResourceBundle *bundle, const char *path, icu::ResourceSink &sink, UErrorCode &errorCode) { - getAllItemsWithFallback(bundle, path, &sink, NULL, NULL, errorCode); -} - -U_CAPI void U_EXPORT2 -ures_getAllArrayItemsWithFallback(const UResourceBundle *bundle, const char *path, - ResourceArraySink &sink, UErrorCode &errorCode) { - getAllItemsWithFallback(bundle, path, NULL, &sink, NULL, 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, NULL, &sink, errorCode); + getAllItemsWithFallback(bundle, path, NULL, &sink, errorCode); } U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, const char* inKey, UResourceBundle *fillIn, UErrorCode *status) { diff --git a/icu4c/source/common/uresdata.cpp b/icu4c/source/common/uresdata.cpp index 761f1f2daad..51d835597cc 100644 --- a/icu4c/source/common/uresdata.cpp +++ b/icu4c/source/common/uresdata.cpp @@ -852,7 +852,6 @@ ures_getAllTableItems(const ResourceData *pResData, Resource table, errorCode = U_RESOURCE_TYPE_MISMATCH; return; } - sink.enter(length, errorCode); if(U_FAILURE(errorCode)) { return; } for (int32_t i = 0; i < length; ++i) { @@ -870,10 +869,8 @@ ures_getAllTableItems(const ResourceData *pResData, Resource table, } int32_t type = RES_GET_TYPE(res); if (URES_IS_ARRAY(type)) { - icu::ResourceArraySink *subSink = sink.getOrCreateArraySink(key, errorCode); - if (subSink != NULL) { - ures_getAllArrayItems(pResData, res, value, *subSink, errorCode); - } + // 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) { @@ -892,7 +889,6 @@ ures_getAllTableItems(const ResourceData *pResData, Resource table, } if(U_FAILURE(errorCode)) { return; } } - sink.leave(errorCode); } UBool icu::ResourceTable::getKeyAndValue(int32_t i, @@ -943,65 +939,6 @@ res_getArrayItem(const ResourceData *pResData, Resource array, int32_t indexR) { return RES_BOGUS; } -U_CFUNC void -ures_getAllArrayItems(const ResourceData *pResData, Resource array, - icu::ResourceDataValue &value, icu::ResourceArraySink &sink, - UErrorCode &errorCode) { - if(U_FAILURE(errorCode)) { return; } - const uint16_t *items16 = NULL; - const Resource *items32 = NULL; - uint32_t offset=RES_GET_OFFSET(array); - int32_t length = 0; - switch(RES_GET_TYPE(array)) { - case URES_ARRAY: - if (offset!=0) { // empty if offset==0 - items32 = (const Resource *)pResData->pRoot+offset; - length = *items32++; - } - break; - case URES_ARRAY16: - items16 = pResData->p16BitUnits+offset; - length = *items16++; - break; - default: - errorCode = U_RESOURCE_TYPE_MISMATCH; - return; - } - sink.enter(length, errorCode); - if(U_FAILURE(errorCode)) { return; } - - for (int32_t i = 0; i < length; ++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::ResourceArraySink *subSink = sink.getOrCreateArraySink(i, errorCode); - if (subSink != NULL) { - ures_getAllArrayItems(pResData, res, value, *subSink, errorCode); - } - } else if (URES_IS_TABLE(type)) { - icu::ResourceTableSink *subSink = sink.getOrCreateTableSink(i, 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 { - value.setResource(res); - sink.put(i, value, errorCode); - } - if(U_FAILURE(errorCode)) { return; } - } - sink.leave(errorCode); -} - uint32_t icu::ResourceArray::internalGetResource(const ResourceData *pResData, int32_t i) const { if (items16 != NULL) { return makeResourceFrom16(pResData, items16[i]); diff --git a/icu4c/source/common/uresdata.h b/icu4c/source/common/uresdata.h index dfd69279951..77b3c3d5de3 100644 --- a/icu4c/source/common/uresdata.h +++ b/icu4c/source/common/uresdata.h @@ -514,15 +514,6 @@ ures_getAllTableItems(const ResourceData *pResData, Resource table, icu::ResourceDataValue &value, icu::ResourceTableSink &sink, UErrorCode &errorCode); -/** - * @param value will be set during enumeration; input contents is ignored - * @param sink receives all array item values - */ -U_CFUNC void -ures_getAllArrayItems(const ResourceData *pResData, Resource array, - icu::ResourceDataValue &value, icu::ResourceArraySink &sink, - UErrorCode &errorCode); - #endif /* __cplusplus */ /** diff --git a/icu4c/source/common/uresimp.h b/icu4c/source/common/uresimp.h index 4612f9d3320..f2b26bd4a41 100644 --- a/icu4c/source/common/uresimp.h +++ b/icu4c/source/common/uresimp.h @@ -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_getAllArrayItemsWithFallback(const UResourceBundle *bundle, const char *path, - icu::ResourceArraySink &sink, UErrorCode &errorCode); - U_CAPI void U_EXPORT2 ures_getAllTableItemsWithFallback(const UResourceBundle *bundle, const char *path, icu::ResourceTableSink &sink, UErrorCode &errorCode);