Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/ucat.h
48729 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3**********************************************************************4* Copyright (c) 2003-2004, International Business Machines5* Corporation and others. All Rights Reserved.6**********************************************************************7* Author: Alan Liu8* Created: March 19 20039* Since: ICU 2.610**********************************************************************11*/12#ifndef UCAT_H13#define UCAT_H1415#include "unicode/utypes.h"16#include "unicode/ures.h"1718/**19* \file20* \brief C API: Message Catalog Wrappers21*22* This C API provides look-alike functions that deliberately resemble23* the POSIX catopen, catclose, and catgets functions. The underlying24* implementation is in terms of ICU resource bundles, rather than25* POSIX message catalogs.26*27* The ICU resource bundles obey standard ICU inheritance policies.28* To facilitate this, sets and messages are flattened into one tier.29* This is done by creating resource bundle keys of the form30* <set_num>%<msg_num> where set_num is the set number and msg_num is31* the message number, formatted as decimal strings.32*33* Example: Consider a message catalog containing two sets:34*35* Set 1: Message 4 = "Good morning."36* Message 5 = "Good afternoon."37* Message 7 = "Good evening."38* Message 8 = "Good night."39* Set 4: Message 14 = "Please "40* Message 19 = "Thank you."41* Message 20 = "Sincerely,"42*43* The ICU resource bundle source file would, assuming it is named44* "greet.txt", would look like this:45*46* greet47* {48* 1%4 { "Good morning." }49* 1%5 { "Good afternoon." }50* 1%7 { "Good evening." }51* 1%8 { "Good night." }52*53* 4%14 { "Please " }54* 4%19 { "Thank you." }55* 4%20 { "Sincerely," }56* }57*58* The catgets function is commonly used in combination with functions59* like printf and strftime. ICU components like message format can60* be used instead, although they use a different format syntax.61* There is an ICU package, icuio, that provides some of62* the POSIX-style formatting API.63*/6465U_CDECL_BEGIN6667/**68* An ICU message catalog descriptor, analogous to nl_catd.69*70* @stable ICU 2.671*/72typedef UResourceBundle* u_nl_catd;7374/**75* Open and return an ICU message catalog descriptor. The descriptor76* may be passed to u_catgets() to retrieve localized strings.77*78* @param name string containing the full path pointing to the79* directory where the resources reside followed by the package name80* e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.81* If NULL, ICU default data files will be used.82*83* Unlike POSIX, environment variables are not interpolated within the84* name.85*86* @param locale the locale for which we want to open the resource. If87* NULL, the default ICU locale will be used (see uloc_getDefault). If88* strlen(locale) == 0, the root locale will be used.89*90* @param ec input/output error code. Upon output,91* U_USING_FALLBACK_WARNING indicates that a fallback locale was92* used. For example, 'de_CH' was requested, but nothing was found93* there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the94* default locale data or root locale data was used; neither the95* requested locale nor any of its fallback locales were found.96*97* @return a message catalog descriptor that may be passed to98* u_catgets(). If the ec parameter indicates success, then the caller99* is responsible for calling u_catclose() to close the message100* catalog. If the ec parameter indicates failure, then NULL will be101* returned.102*103* @stable ICU 2.6104*/105U_STABLE u_nl_catd U_EXPORT2106u_catopen(const char* name, const char* locale, UErrorCode* ec);107108/**109* Close an ICU message catalog, given its descriptor.110*111* @param catd a message catalog descriptor to be closed. May be NULL,112* in which case no action is taken.113*114* @stable ICU 2.6115*/116U_STABLE void U_EXPORT2117u_catclose(u_nl_catd catd);118119/**120* Retrieve a localized string from an ICU message catalog.121*122* @param catd a message catalog descriptor returned by u_catopen.123*124* @param set_num the message catalog set number. Sets need not be125* numbered consecutively.126*127* @param msg_num the message catalog message number within the128* set. Messages need not be numbered consecutively.129*130* @param s the default string. This is returned if the string131* specified by the set_num and msg_num is not found. It must be132* zero-terminated.133*134* @param len fill-in parameter to receive the length of the result.135* May be NULL, in which case it is ignored.136*137* @param ec input/output error code. May be U_USING_FALLBACK_WARNING138* or U_USING_DEFAULT_WARNING. U_MISSING_RESOURCE_ERROR indicates that139* the set_num/msg_num tuple does not specify a valid message string140* in this catalog.141*142* @return a pointer to a zero-terminated UChar array which lives in143* an internal buffer area, typically a memory mapped/DLL file. The144* caller must NOT delete this pointer. If the call is unsuccessful145* for any reason, then s is returned. This includes the situation in146* which ec indicates a failing error code upon entry to this147* function.148*149* @stable ICU 2.6150*/151U_STABLE const UChar* U_EXPORT2152u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num,153const UChar* s,154int32_t* len, UErrorCode* ec);155156U_CDECL_END157158#endif /*UCAT_H*/159/*eof*/160161162