Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 **********************************************************************
3 * Copyright (c) 2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: March 19 2003
8 * Since: ICU 2.6
9 **********************************************************************
10 */
11 #include "unicode/ucat.h"
12 #include "unicode/ustring.h"
13 #include "cstring.h"
14 #include "uassert.h"
16 /* Separator between set_num and msg_num */
17 static const char SEPARATOR = '%';
19 /* Maximum length of a set_num/msg_num key, incl. terminating zero.
20 * Longest possible key is "-2147483648%-2147483648" */
21 #define MAX_KEY_LEN (24)
23 /**
24 * Fill in buffer with a set_num/msg_num key string, given the numeric
25 * values. Numeric values must be >= 0. Buffer must be of length
26 * MAX_KEY_LEN or more.
27 */
28 static char*
29 _catkey(char* buffer, int32_t set_num, int32_t msg_num) {
30 int32_t i = 0;
31 i = T_CString_integerToString(buffer, set_num, 10);
32 buffer[i++] = SEPARATOR;
33 T_CString_integerToString(buffer+i, msg_num, 10);
34 return buffer;
35 }
37 U_CAPI u_nl_catd U_EXPORT2
38 u_catopen(const char* name, const char* locale, UErrorCode* ec) {
39 return (u_nl_catd) ures_open(name, locale, ec);
40 }
42 U_CAPI void U_EXPORT2
43 u_catclose(u_nl_catd catd) {
44 ures_close((UResourceBundle*) catd); /* may be NULL */
45 }
47 U_CAPI const UChar* U_EXPORT2
48 u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num,
49 const UChar* s,
50 int32_t* len, UErrorCode* ec) {
52 char key[MAX_KEY_LEN];
53 const UChar* result;
55 if (ec == NULL || U_FAILURE(*ec)) {
56 goto ERROR;
57 }
59 result = ures_getStringByKey((const UResourceBundle*) catd,
60 _catkey(key, set_num, msg_num),
61 len, ec);
62 if (U_FAILURE(*ec)) {
63 goto ERROR;
64 }
66 return result;
68 ERROR:
69 /* In case of any failure, return s */
70 if (len != NULL) {
71 *len = u_strlen(s);
72 }
73 return s;
74 }
76 /*eof*/