]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/ulocdata.c
ICU-8.11.tar.gz
[apple/icu.git] / icuSources / i18n / ulocdata.c
index fffe2faa2310065fc9dc89c1b3e3a699c336c320..68c3d1d034589f0ff31094f32139ed2acc803dfa 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *                                                                            *
-* Copyright (C) 2003-2004, International Business Machines                        *
+* Copyright (C) 2003-2005, International Business Machines                   *
 *                Corporation and others. All Rights Reserved.                *
 *                                                                            *
 ******************************************************************************
 *   indentation:4
 *
 *   created on: 2003Oct21
-*   created by: Ram Viswanadha
+*   created by: Ram Viswanadha,John Emmons
 */
 
+#include "cmemory.h"
+#include "unicode/ustring.h"
 #include "unicode/ulocdata.h"
 
-#define EXEMPLAR_CHARS      "ExemplarCharacters"
 #define MEASUREMENT_SYSTEM  "MeasurementSystem"
 #define PAPER_SIZE          "PaperSize"
 
-U_CAPI USet* U_EXPORT2 
-ulocdata_getExemplarSet(USet *fillIn, const char *localeID,
-                        uint32_t options, UErrorCode *status){
+/** A locale data object.
+ *  For usage in C programs.
+ *  @draft ICU 3.4
+ */
+struct ULocaleData {
+    /**
+     * Controls the "No Substitute" behavior of this locale data object
+     */
+    UBool noSubstitute;
+
+    /**
+     * Pointer to the resource bundle associated with this locale data object
+     */
+    UResourceBundle *bundle;
+};
+
+U_CAPI ULocaleData* U_EXPORT2
+ulocdata_open(const char *localeID, UErrorCode *status)
+{
+   ULocaleData *uld;
+   if (U_FAILURE(*status)) {
+       return NULL;
+   }
+
+   uld = (ULocaleData *)uprv_malloc(sizeof(ULocaleData));
+   if (uld == NULL) {
+      *status = U_MEMORY_ALLOCATION_ERROR;
+      return(NULL);
+   }
+
+    
+   uld->noSubstitute = FALSE;
+   uld->bundle = ures_open(NULL, localeID, status);
+
+   if (U_FAILURE(*status)) {
+      uprv_free(uld);
+      return NULL;
+   }
+
+   return uld;
+}
+
+U_CAPI void U_EXPORT2
+ulocdata_close(ULocaleData *uld)
+{
+    if ( uld != NULL ) {
+       ures_close(uld->bundle);
+       uprv_free(uld);
+    } 
+}
+
+U_CAPI void U_EXPORT2
+ulocdata_setNoSubstitute(ULocaleData *uld, UBool setting)
+{
+   uld->noSubstitute = setting;
+}
+
+U_CAPI UBool U_EXPORT2
+ulocdata_getNoSubstitute(ULocaleData *uld)
+{
+   return uld->noSubstitute;
+}
+
+U_CAPI USet* U_EXPORT2
+ulocdata_getExemplarSet(ULocaleData *uld, USet *fillIn, 
+                        uint32_t options, ULocaleDataExemplarSetType extype, UErrorCode *status){
     
-    UResourceBundle *bundle = NULL;
+    const char* exemplarSetTypes[] = { "ExemplarCharacters", "AuxExemplarCharacters" };
     const UChar *exemplarChars = NULL;
     int32_t len = 0;
     UErrorCode localStatus = U_ZERO_ERROR;
 
-    if (U_FAILURE(*status)){
+    if (U_FAILURE(*status))
         return NULL;
-    }
     
-    bundle = ures_open(NULL, localeID, status);
-    if (U_FAILURE(*status)) {
-        return NULL;
+    exemplarChars = ures_getStringByKey(uld->bundle, exemplarSetTypes[extype], &len, &localStatus);
+    if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+        localStatus = U_MISSING_RESOURCE_ERROR;
     }
-    
-    exemplarChars = ures_getStringByKey(bundle, EXEMPLAR_CHARS, &len, &localStatus);
-    if (U_FAILURE(localStatus) || (*status != U_USING_DEFAULT_WARNING && localStatus != U_ZERO_ERROR)) {
+       
+    if (localStatus != U_ZERO_ERROR) {
         *status = localStatus;
     }
     
-    if(fillIn != NULL){
+    if (U_FAILURE(*status))
+        return NULL;
+    
+    if(fillIn != NULL)
         uset_applyPattern(fillIn, exemplarChars, len, 
                           USET_IGNORE_SPACE | options, status);
-    }else{
+    else
         fillIn = uset_openPatternOptions(exemplarChars, len,
                                          USET_IGNORE_SPACE | options, status);
-    }
     
-    ures_close(bundle);
-
     return fillIn;
 
 }
 
+U_CAPI int32_t U_EXPORT2
+ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type, 
+                      UChar *result, int32_t resultLength, UErrorCode *status){
+
+    const char* delimiterKeys[] =  { "quotationStart",
+                                     "quotationEnd",
+                                     "alternateQuotationStart",
+                                     "alternateQuotationEnd" };
+
+    UResourceBundle *delimiterBundle;
+    int32_t len = 0;
+    const UChar *delimiter = NULL;
+    UErrorCode localStatus = U_ZERO_ERROR;
+
+    if (U_FAILURE(*status))
+        return 0;
+
+    delimiterBundle = ures_getByKey(uld->bundle, "delimiters", NULL, &localStatus);
+
+    if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+        localStatus = U_MISSING_RESOURCE_ERROR;
+    }
+
+    if (localStatus != U_ZERO_ERROR) {
+        *status = localStatus;
+    }
+
+    if (U_FAILURE(*status)){
+        ures_close(delimiterBundle);
+        return 0;
+    }
+
+    delimiter = ures_getStringByKey(delimiterBundle, delimiterKeys[type], &len, &localStatus);
+    ures_close(delimiterBundle);
+
+    if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+        localStatus = U_MISSING_RESOURCE_ERROR;
+    }
+
+    if (localStatus != U_ZERO_ERROR) {
+        *status = localStatus;
+    }
+    
+    if (U_FAILURE(*status)){
+        return 0;
+    }
+        
+    u_strncpy(result,delimiter,resultLength);
+    return len;
+}
+
 U_CAPI UMeasurementSystem U_EXPORT2
 ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){