xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/ucat.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker **********************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 2003-2004, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker * Corporation and others.  All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker **********************************************************************
8*0e209d39SAndroid Build Coastguard Worker * Author: Alan Liu
9*0e209d39SAndroid Build Coastguard Worker * Created: March 19 2003
10*0e209d39SAndroid Build Coastguard Worker * Since: ICU 2.6
11*0e209d39SAndroid Build Coastguard Worker **********************************************************************
12*0e209d39SAndroid Build Coastguard Worker */
13*0e209d39SAndroid Build Coastguard Worker #ifndef UCAT_H
14*0e209d39SAndroid Build Coastguard Worker #define UCAT_H
15*0e209d39SAndroid Build Coastguard Worker 
16*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
17*0e209d39SAndroid Build Coastguard Worker #include "unicode/ures.h"
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker /**
20*0e209d39SAndroid Build Coastguard Worker  * \file
21*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Message Catalog Wrappers
22*0e209d39SAndroid Build Coastguard Worker  *
23*0e209d39SAndroid Build Coastguard Worker  * This C API provides look-alike functions that deliberately resemble
24*0e209d39SAndroid Build Coastguard Worker  * the POSIX catopen, catclose, and catgets functions.  The underlying
25*0e209d39SAndroid Build Coastguard Worker  * implementation is in terms of ICU resource bundles, rather than
26*0e209d39SAndroid Build Coastguard Worker  * POSIX message catalogs.
27*0e209d39SAndroid Build Coastguard Worker  *
28*0e209d39SAndroid Build Coastguard Worker  * The ICU resource bundles obey standard ICU inheritance policies.
29*0e209d39SAndroid Build Coastguard Worker  * To facilitate this, sets and messages are flattened into one tier.
30*0e209d39SAndroid Build Coastguard Worker  * This is done by creating resource bundle keys of the form
31*0e209d39SAndroid Build Coastguard Worker  * <set_num>%<msg_num> where set_num is the set number and msg_num is
32*0e209d39SAndroid Build Coastguard Worker  * the message number, formatted as decimal strings.
33*0e209d39SAndroid Build Coastguard Worker  *
34*0e209d39SAndroid Build Coastguard Worker  * Example:  Consider a message catalog containing two sets:
35*0e209d39SAndroid Build Coastguard Worker  *
36*0e209d39SAndroid Build Coastguard Worker  * Set 1: Message 4  = "Good morning."
37*0e209d39SAndroid Build Coastguard Worker  *        Message 5  = "Good afternoon."
38*0e209d39SAndroid Build Coastguard Worker  *        Message 7  = "Good evening."
39*0e209d39SAndroid Build Coastguard Worker  *        Message 8  = "Good night."
40*0e209d39SAndroid Build Coastguard Worker  * Set 4: Message 14 = "Please "
41*0e209d39SAndroid Build Coastguard Worker  *        Message 19 = "Thank you."
42*0e209d39SAndroid Build Coastguard Worker  *        Message 20 = "Sincerely,"
43*0e209d39SAndroid Build Coastguard Worker  *
44*0e209d39SAndroid Build Coastguard Worker  * The ICU resource bundle source file would, assuming it is named
45*0e209d39SAndroid Build Coastguard Worker  * "greet.txt", would look like this:
46*0e209d39SAndroid Build Coastguard Worker  *
47*0e209d39SAndroid Build Coastguard Worker  * greet
48*0e209d39SAndroid Build Coastguard Worker  * {
49*0e209d39SAndroid Build Coastguard Worker  *     1%4  { "Good morning." }
50*0e209d39SAndroid Build Coastguard Worker  *     1%5  { "Good afternoon." }
51*0e209d39SAndroid Build Coastguard Worker  *     1%7  { "Good evening." }
52*0e209d39SAndroid Build Coastguard Worker  *     1%8  { "Good night." }
53*0e209d39SAndroid Build Coastguard Worker  *
54*0e209d39SAndroid Build Coastguard Worker  *     4%14 { "Please " }
55*0e209d39SAndroid Build Coastguard Worker  *     4%19 { "Thank you." }
56*0e209d39SAndroid Build Coastguard Worker  *     4%20 { "Sincerely," }
57*0e209d39SAndroid Build Coastguard Worker  * }
58*0e209d39SAndroid Build Coastguard Worker  *
59*0e209d39SAndroid Build Coastguard Worker  * The catgets function is commonly used in combination with functions
60*0e209d39SAndroid Build Coastguard Worker  * like printf and strftime.  ICU components like message format can
61*0e209d39SAndroid Build Coastguard Worker  * be used instead, although they use a different format syntax.
62*0e209d39SAndroid Build Coastguard Worker  * There is an ICU package, icuio, that provides some of
63*0e209d39SAndroid Build Coastguard Worker  * the POSIX-style formatting API.
64*0e209d39SAndroid Build Coastguard Worker  */
65*0e209d39SAndroid Build Coastguard Worker 
66*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
67*0e209d39SAndroid Build Coastguard Worker 
68*0e209d39SAndroid Build Coastguard Worker /**
69*0e209d39SAndroid Build Coastguard Worker  * An ICU message catalog descriptor, analogous to nl_catd.
70*0e209d39SAndroid Build Coastguard Worker  *
71*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
72*0e209d39SAndroid Build Coastguard Worker  */
73*0e209d39SAndroid Build Coastguard Worker typedef UResourceBundle* u_nl_catd;
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker /**
76*0e209d39SAndroid Build Coastguard Worker  * Open and return an ICU message catalog descriptor. The descriptor
77*0e209d39SAndroid Build Coastguard Worker  * may be passed to u_catgets() to retrieve localized strings.
78*0e209d39SAndroid Build Coastguard Worker  *
79*0e209d39SAndroid Build Coastguard Worker  * @param name string containing the full path pointing to the
80*0e209d39SAndroid Build Coastguard Worker  * directory where the resources reside followed by the package name
81*0e209d39SAndroid Build Coastguard Worker  * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.
82*0e209d39SAndroid Build Coastguard Worker  * If NULL, ICU default data files will be used.
83*0e209d39SAndroid Build Coastguard Worker  *
84*0e209d39SAndroid Build Coastguard Worker  * Unlike POSIX, environment variables are not interpolated within the
85*0e209d39SAndroid Build Coastguard Worker  * name.
86*0e209d39SAndroid Build Coastguard Worker  *
87*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale for which we want to open the resource. If
88*0e209d39SAndroid Build Coastguard Worker  * NULL, the default ICU locale will be used (see uloc_getDefault). If
89*0e209d39SAndroid Build Coastguard Worker  * strlen(locale) == 0, the root locale will be used.
90*0e209d39SAndroid Build Coastguard Worker  *
91*0e209d39SAndroid Build Coastguard Worker  * @param ec input/output error code. Upon output,
92*0e209d39SAndroid Build Coastguard Worker  * U_USING_FALLBACK_WARNING indicates that a fallback locale was
93*0e209d39SAndroid Build Coastguard Worker  * used. For example, 'de_CH' was requested, but nothing was found
94*0e209d39SAndroid Build Coastguard Worker  * there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the
95*0e209d39SAndroid Build Coastguard Worker  * default locale data or root locale data was used; neither the
96*0e209d39SAndroid Build Coastguard Worker  * requested locale nor any of its fallback locales were found.
97*0e209d39SAndroid Build Coastguard Worker  *
98*0e209d39SAndroid Build Coastguard Worker  * @return a message catalog descriptor that may be passed to
99*0e209d39SAndroid Build Coastguard Worker  * u_catgets(). If the ec parameter indicates success, then the caller
100*0e209d39SAndroid Build Coastguard Worker  * is responsible for calling u_catclose() to close the message
101*0e209d39SAndroid Build Coastguard Worker  * catalog. If the ec parameter indicates failure, then NULL will be
102*0e209d39SAndroid Build Coastguard Worker  * returned.
103*0e209d39SAndroid Build Coastguard Worker  *
104*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
105*0e209d39SAndroid Build Coastguard Worker  */
106*0e209d39SAndroid Build Coastguard Worker U_CAPI u_nl_catd U_EXPORT2
107*0e209d39SAndroid Build Coastguard Worker u_catopen(const char* name, const char* locale, UErrorCode* ec);
108*0e209d39SAndroid Build Coastguard Worker 
109*0e209d39SAndroid Build Coastguard Worker /**
110*0e209d39SAndroid Build Coastguard Worker  * Close an ICU message catalog, given its descriptor.
111*0e209d39SAndroid Build Coastguard Worker  *
112*0e209d39SAndroid Build Coastguard Worker  * @param catd a message catalog descriptor to be closed. May be NULL,
113*0e209d39SAndroid Build Coastguard Worker  * in which case no action is taken.
114*0e209d39SAndroid Build Coastguard Worker  *
115*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
116*0e209d39SAndroid Build Coastguard Worker  */
117*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
118*0e209d39SAndroid Build Coastguard Worker u_catclose(u_nl_catd catd);
119*0e209d39SAndroid Build Coastguard Worker 
120*0e209d39SAndroid Build Coastguard Worker /**
121*0e209d39SAndroid Build Coastguard Worker  * Retrieve a localized string from an ICU message catalog.
122*0e209d39SAndroid Build Coastguard Worker  *
123*0e209d39SAndroid Build Coastguard Worker  * @param catd a message catalog descriptor returned by u_catopen.
124*0e209d39SAndroid Build Coastguard Worker  *
125*0e209d39SAndroid Build Coastguard Worker  * @param set_num the message catalog set number. Sets need not be
126*0e209d39SAndroid Build Coastguard Worker  * numbered consecutively.
127*0e209d39SAndroid Build Coastguard Worker  *
128*0e209d39SAndroid Build Coastguard Worker  * @param msg_num the message catalog message number within the
129*0e209d39SAndroid Build Coastguard Worker  * set. Messages need not be numbered consecutively.
130*0e209d39SAndroid Build Coastguard Worker  *
131*0e209d39SAndroid Build Coastguard Worker  * @param s the default string. This is returned if the string
132*0e209d39SAndroid Build Coastguard Worker  * specified by the set_num and msg_num is not found. It must be
133*0e209d39SAndroid Build Coastguard Worker  * zero-terminated.
134*0e209d39SAndroid Build Coastguard Worker  *
135*0e209d39SAndroid Build Coastguard Worker  * @param len fill-in parameter to receive the length of the result.
136*0e209d39SAndroid Build Coastguard Worker  * May be NULL, in which case it is ignored.
137*0e209d39SAndroid Build Coastguard Worker  *
138*0e209d39SAndroid Build Coastguard Worker  * @param ec input/output error code. May be U_USING_FALLBACK_WARNING
139*0e209d39SAndroid Build Coastguard Worker  * or U_USING_DEFAULT_WARNING. U_MISSING_RESOURCE_ERROR indicates that
140*0e209d39SAndroid Build Coastguard Worker  * the set_num/msg_num tuple does not specify a valid message string
141*0e209d39SAndroid Build Coastguard Worker  * in this catalog.
142*0e209d39SAndroid Build Coastguard Worker  *
143*0e209d39SAndroid Build Coastguard Worker  * @return a pointer to a zero-terminated UChar array which lives in
144*0e209d39SAndroid Build Coastguard Worker  * an internal buffer area, typically a memory mapped/DLL file. The
145*0e209d39SAndroid Build Coastguard Worker  * caller must NOT delete this pointer. If the call is unsuccessful
146*0e209d39SAndroid Build Coastguard Worker  * for any reason, then s is returned.  This includes the situation in
147*0e209d39SAndroid Build Coastguard Worker  * which ec indicates a failing error code upon entry to this
148*0e209d39SAndroid Build Coastguard Worker  * function.
149*0e209d39SAndroid Build Coastguard Worker  *
150*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
151*0e209d39SAndroid Build Coastguard Worker  */
152*0e209d39SAndroid Build Coastguard Worker U_CAPI const UChar* U_EXPORT2
153*0e209d39SAndroid Build Coastguard Worker u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num,
154*0e209d39SAndroid Build Coastguard Worker           const UChar* s,
155*0e209d39SAndroid Build Coastguard Worker           int32_t* len, UErrorCode* ec);
156*0e209d39SAndroid Build Coastguard Worker 
157*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
158*0e209d39SAndroid Build Coastguard Worker 
159*0e209d39SAndroid Build Coastguard Worker #endif /*UCAT_H*/
160*0e209d39SAndroid Build Coastguard Worker /*eof*/
161