- uprv_memcpy(opts, src.opts, sizeof(UColOptionSet));
- ucol_setOptionsFromHeader(result, opts, status);
- result->freeOptionsOnClose = TRUE;
- result->hasRealData = FALSE;
- result->freeImageOnClose = FALSE;
- }
-
- if(U_SUCCESS(*status)) {
- UChar *newRules;
- result->dataVersion[0] = UCOL_BUILDER_VERSION;
- if(rulesLength > 0) {
- newRules = (UChar *)uprv_malloc((rulesLength+1)*U_SIZEOF_UCHAR);
- /* test for NULL */
- if (newRules == NULL) {
- *status = U_MEMORY_ALLOCATION_ERROR;
- goto cleanup;
- }
- uprv_memcpy(newRules, rules, rulesLength*U_SIZEOF_UCHAR);
- newRules[rulesLength]=0;
- result->rules = newRules;
- result->rulesLength = rulesLength;
- result->freeRulesOnClose = TRUE;
- }
- result->rb = NULL;
- result->elements = NULL;
- result->validLocale = NULL;
- result->requestedLocale = NULL;
- ucol_setAttribute(result, UCOL_STRENGTH, strength, status);
- ucol_setAttribute(result, UCOL_NORMALIZATION_MODE, norm, status);
- } else {
-cleanup:
- if(result != NULL) {
- ucol_close(result);
+
+ if(src.resultLen > 0 || src.removeSet != NULL) { /* we have a set of rules, let's make something of it */
+ /* also, if we wanted to remove some contractions, we should make a tailoring */
+ table = ucol_assembleTailoringTable(&src, status);
+ if(U_SUCCESS(*status)) {
+ // builder version
+ table->version[0] = UCOL_BUILDER_VERSION;
+ // no tailoring information on this level
+ table->version[1] = table->version[2] = table->version[3] = 0;
+ // set UCD version
+ u_getUnicodeVersion(table->UCDVersion);
+ // set UCA version
+ uprv_memcpy(table->UCAVersion, UCA->image->UCAVersion, sizeof(UVersionInfo));
+ result = ucol_initCollator(table, 0, UCA, status);
+ if (U_FAILURE(*status)) {
+ goto cleanup;
+ }
+ result->hasRealData = TRUE;
+ result->freeImageOnClose = TRUE;
+ }
+ } else { /* no rules, but no error either */
+ // must be only options
+ // We will init the collator from UCA
+ result = ucol_initCollator(UCA->image, 0, UCA, status);
+ // Check for null result
+ if (U_FAILURE(*status)) {
+ goto cleanup;
+ }
+ // And set only the options
+ UColOptionSet *opts = (UColOptionSet *)uprv_malloc(sizeof(UColOptionSet));
+ /* test for NULL */
+ if (opts == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup;
+ }
+ uprv_memcpy(opts, src.opts, sizeof(UColOptionSet));
+ ucol_setOptionsFromHeader(result, opts, status);
+ result->freeOptionsOnClose = TRUE;
+ result->hasRealData = FALSE;
+ result->freeImageOnClose = FALSE;
+ }
+
+ if(U_SUCCESS(*status)) {
+ UChar *newRules;
+ result->dataVersion[0] = UCOL_BUILDER_VERSION;
+ if(rulesLength > 0) {
+ newRules = (UChar *)uprv_malloc((rulesLength+1)*U_SIZEOF_UCHAR);
+ /* test for NULL */
+ if (newRules == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup;
+ }
+ uprv_memcpy(newRules, rules, rulesLength*U_SIZEOF_UCHAR);
+ newRules[rulesLength]=0;
+ result->rules = newRules;
+ result->rulesLength = rulesLength;
+ result->freeRulesOnClose = TRUE;
+ }
+ result->ucaRules = NULL;
+ result->actualLocale = NULL;
+ result->validLocale = NULL;
+ result->requestedLocale = NULL;
+ ucol_setAttribute(result, UCOL_STRENGTH, strength, status);
+ ucol_setAttribute(result, UCOL_NORMALIZATION_MODE, norm, status);