~ubuntu-branches/ubuntu/gutsy/icu/gutsy

« back to all changes in this revision

Viewing changes to source/i18n/ucol.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2005-05-21 22:44:31 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: package-import@ubuntu.com-20050521224431-r7rktfhnu1n4tf1g
Tags: 2.1-2.1
Rename icu-doc to icu21-doc. icu-doc is built by the icu28 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
283
283
    result = ucol_initCollator(UCA->image, result, status);
284
284
    // if we use UCA, real locale is root
285
285
    result->rb = ures_open(NULL, "", status);
 
286
    result->binary = ures_open(NULL, "", status);
286
287
    if(U_FAILURE(*status)) {
287
288
      goto clean;
288
289
    }
309
310
      }
310
311
      result->hasRealData = FALSE;
311
312
    }
312
 
    const char *realCollationDataLocale = ures_getLocale(binary, status);
313
 
    ures_close(binary);
314
 
    // if the real data came from the fallback, we want to drag around 
315
 
    // the real resource bundle
316
 
    if(uprv_strcmp(ures_getLocale(b, status), realCollationDataLocale) != 0) {
317
 
      result->rb = ures_open(NULL, realCollationDataLocale, status);
318
 
      if(U_FAILURE(*status)) {
319
 
        goto clean;
320
 
      }
321
 
      ures_close(b);
322
 
    } else { // otherwise, we'll keep the initial RB around
323
 
      result->rb = b;
324
 
    }
 
313
    result->binary = binary;
 
314
    result->rb = b;
325
315
  } else { /* There is another error, and we're just gonna clean up */
326
316
clean:
327
317
    ures_close(b);
328
318
    ures_close(binary);
329
319
    return NULL;
330
320
  }
 
321
  if(loc == NULL) {
 
322
    loc = ures_getLocale(result->rb, status);
 
323
  }
 
324
  result->requestedLocale = (char *)uprv_malloc((uprv_strlen(loc)+1)*sizeof(char));
 
325
  uprv_strcpy(result->requestedLocale, loc);
331
326
  return result;
332
327
}
333
328
 
378
373
  } else if(coll->hasRealData == TRUE) {
379
374
    uprv_free((UCATableHeader *)coll->image);
380
375
  }
 
376
  if(coll->binary != NULL) {
 
377
    ures_close(coll->binary);
 
378
  }
 
379
  if(coll->requestedLocale != NULL) {
 
380
    uprv_free(coll->requestedLocale);
 
381
  }
381
382
  uprv_free(coll);
382
383
}
383
384
 
484
485
    result->rules = newRules;
485
486
    result->rulesLength = rulesLength;
486
487
    result->freeRulesOnClose = TRUE;
487
 
    result->rb = 0;
 
488
    result->rb = NULL;
 
489
    result->binary = NULL;
 
490
    result->requestedLocale = NULL;
488
491
    ucol_setAttribute(result, UCOL_STRENGTH, strength, status);
489
492
    ucol_setAttribute(result, UCOL_NORMALIZATION_MODE, norm, status);
490
493
  } else {
5658
5661
 
5659
5662
/* returns the locale name the collation data comes from */
5660
5663
U_CAPI const char * U_EXPORT2
5661
 
ucol_getLocale(const UCollator *coll, UErrorCode *status) {
 
5664
ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status) {
 
5665
  const char *result = NULL;
5662
5666
  if(status == NULL || U_FAILURE(*status)) {
5663
5667
    return NULL;
5664
5668
  }
5665
 
  if(coll->rb != NULL) {
5666
 
    return ures_getLocale(coll->rb, status);
5667
 
  } else {
5668
 
    return NULL;
 
5669
  switch(type) {
 
5670
  case ULOC_ACTUAL_LOCALE:
 
5671
    if(coll->binary != NULL) {
 
5672
      result = ures_getLocale(coll->binary, status);
 
5673
    }
 
5674
    break;
 
5675
  case ULOC_VALID_LOCALE:
 
5676
    if(coll->rb != NULL) {
 
5677
      result = ures_getLocale(coll->rb, status);
 
5678
    } 
 
5679
    break;
 
5680
  case ULOC_REQUESTED_LOCALE:
 
5681
    result = coll->requestedLocale;
 
5682
    break;
 
5683
  default:
 
5684
    *status = U_ILLEGAL_ARGUMENT_ERROR;
5669
5685
  }
 
5686
  return result;
5670
5687
}
5671
5688