intl/icu/source/common/unicode/ucat.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial