michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (c) 2003, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Author: Alan Liu michael@0: * Created: March 19 2003 michael@0: * Since: ICU 2.6 michael@0: ********************************************************************** michael@0: */ michael@0: #include "unicode/ucat.h" michael@0: #include "unicode/ustring.h" michael@0: #include "cstring.h" michael@0: #include "uassert.h" michael@0: michael@0: /* Separator between set_num and msg_num */ michael@0: static const char SEPARATOR = '%'; michael@0: michael@0: /* Maximum length of a set_num/msg_num key, incl. terminating zero. michael@0: * Longest possible key is "-2147483648%-2147483648" */ michael@0: #define MAX_KEY_LEN (24) michael@0: michael@0: /** michael@0: * Fill in buffer with a set_num/msg_num key string, given the numeric michael@0: * values. Numeric values must be >= 0. Buffer must be of length michael@0: * MAX_KEY_LEN or more. michael@0: */ michael@0: static char* michael@0: _catkey(char* buffer, int32_t set_num, int32_t msg_num) { michael@0: int32_t i = 0; michael@0: i = T_CString_integerToString(buffer, set_num, 10); michael@0: buffer[i++] = SEPARATOR; michael@0: T_CString_integerToString(buffer+i, msg_num, 10); michael@0: return buffer; michael@0: } michael@0: michael@0: U_CAPI u_nl_catd U_EXPORT2 michael@0: u_catopen(const char* name, const char* locale, UErrorCode* ec) { michael@0: return (u_nl_catd) ures_open(name, locale, ec); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: u_catclose(u_nl_catd catd) { michael@0: ures_close((UResourceBundle*) catd); /* may be NULL */ michael@0: } michael@0: michael@0: U_CAPI const UChar* U_EXPORT2 michael@0: u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num, michael@0: const UChar* s, michael@0: int32_t* len, UErrorCode* ec) { michael@0: michael@0: char key[MAX_KEY_LEN]; michael@0: const UChar* result; michael@0: michael@0: if (ec == NULL || U_FAILURE(*ec)) { michael@0: goto ERROR; michael@0: } michael@0: michael@0: result = ures_getStringByKey((const UResourceBundle*) catd, michael@0: _catkey(key, set_num, msg_num), michael@0: len, ec); michael@0: if (U_FAILURE(*ec)) { michael@0: goto ERROR; michael@0: } michael@0: michael@0: return result; michael@0: michael@0: ERROR: michael@0: /* In case of any failure, return s */ michael@0: if (len != NULL) { michael@0: *len = u_strlen(s); michael@0: } michael@0: return s; michael@0: } michael@0: michael@0: /*eof*/