os/textandloc/fontservices/textshaperplugin/IcuSource/common/uresimp.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
**********************************************************************
sl@0
     3
*   Copyright (C) 2000-2005, International Business Machines
sl@0
     4
*   Corporation and others.  All Rights Reserved.
sl@0
     5
**********************************************************************
sl@0
     6
*/
sl@0
     7
sl@0
     8
#ifndef URESIMP_H
sl@0
     9
#define URESIMP_H
sl@0
    10
sl@0
    11
#include "unicode/ures.h"
sl@0
    12
sl@0
    13
#include "uresdata.h"
sl@0
    14
sl@0
    15
#define kRootLocaleName         "root"
sl@0
    16
sl@0
    17
/*
sl@0
    18
 The default minor version and the version separator must be exactly one
sl@0
    19
 character long.
sl@0
    20
*/
sl@0
    21
sl@0
    22
#define kDefaultMinorVersion    "0"
sl@0
    23
#define kVersionSeparator       "."
sl@0
    24
#define kVersionTag             "Version"
sl@0
    25
sl@0
    26
#define MAGIC1 19700503
sl@0
    27
#define MAGIC2 19641227
sl@0
    28
sl@0
    29
#define URES_MAX_ALIAS_LEVEL 256
sl@0
    30
#define URES_MAX_BUFFER_SIZE 256
sl@0
    31
sl@0
    32
/*
sl@0
    33
enum UResEntryType {
sl@0
    34
    ENTRY_OK = 0,
sl@0
    35
    ENTRY_GOTO_ROOT = 1,
sl@0
    36
    ENTRY_GOTO_DEFAULT = 2,
sl@0
    37
    ENTRY_INVALID = 3
sl@0
    38
};
sl@0
    39
sl@0
    40
typedef enum UResEntryType UResEntryType;
sl@0
    41
*/
sl@0
    42
sl@0
    43
struct UResourceDataEntry;
sl@0
    44
typedef struct UResourceDataEntry UResourceDataEntry;
sl@0
    45
sl@0
    46
struct UResourceDataEntry {
sl@0
    47
    char *fName; /* name of the locale for bundle - still to decide whether it is original or fallback */
sl@0
    48
    char *fPath; /* path to bundle - used for distinguishing between resources with the same name */
sl@0
    49
    uint32_t fCountExisting; /* how much is this resource used */
sl@0
    50
    ResourceData fData; /* data for low level access */
sl@0
    51
    UResourceDataEntry *fParent; /*next resource in fallback chain*/
sl@0
    52
/*    UResEntryType fStatus;*/
sl@0
    53
    UErrorCode fBogus;
sl@0
    54
    int32_t fHashKey; /* for faster access in the hashtable */
sl@0
    55
};
sl@0
    56
sl@0
    57
#define RES_BUFSIZE 64
sl@0
    58
#define RES_PATH_SEPARATOR   '/'
sl@0
    59
#define RES_PATH_SEPARATOR_S   "/"
sl@0
    60
sl@0
    61
struct UResourceBundle {
sl@0
    62
    const char *fKey; /*tag*/
sl@0
    63
    UResourceDataEntry *fData; /*for low-level access*/
sl@0
    64
    char *fVersion;
sl@0
    65
    char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
sl@0
    66
    char fResBuf[RES_BUFSIZE];
sl@0
    67
    int32_t fResPathLen;
sl@0
    68
    UBool fHasFallback;
sl@0
    69
    UBool fIsTopLevel;
sl@0
    70
    uint32_t fMagic1;   /* For determining if it's a stack object */
sl@0
    71
    uint32_t fMagic2;   /* For determining if it's a stack object */
sl@0
    72
    int32_t fIndex;
sl@0
    73
    int32_t fSize;
sl@0
    74
    ResourceData fResData;
sl@0
    75
    Resource fRes;
sl@0
    76
sl@0
    77
    UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
sl@0
    78
    const UResourceBundle *fParentRes; /* needed to get the actual locale for a child resource */
sl@0
    79
sl@0
    80
};
sl@0
    81
sl@0
    82
U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
sl@0
    83
sl@0
    84
/* Some getters used by the copy constructor */
sl@0
    85
U_CFUNC const char* ures_getName(const UResourceBundle* resB);
sl@0
    86
U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
sl@0
    87
U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);
sl@0
    88
/*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
sl@0
    89
U_CFUNC void ures_freeResPath(UResourceBundle *resB);
sl@0
    90
sl@0
    91
/* Candidates for export */
sl@0
    92
U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
sl@0
    93
sl@0
    94
/**
sl@0
    95
 * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
sl@0
    96
 * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
sl@0
    97
 * need to reference data in named structures, while indexes can reference both named and anonymous resources.
sl@0
    98
 * Features a fill-in parameter. 
sl@0
    99
 * 
sl@0
   100
 * Note, this function does NOT have a syntax for specifying items within a tree.  May want to consider a
sl@0
   101
 * syntax that delineates between package/tree and resource.  
sl@0
   102
 *
sl@0
   103
 * @param pathToResource    a path that will lead to the requested resource
sl@0
   104
 * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
sl@0
   105
 *                          Alternatively, you can supply a struct to be filled by this function.
sl@0
   106
 * @param status            fills in the outgoing error code.
sl@0
   107
 * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
sl@0
   108
 * @draft ICU 2.2
sl@0
   109
 */
sl@0
   110
U_CAPI UResourceBundle* U_EXPORT2
sl@0
   111
ures_findResource(const char* pathToResource, 
sl@0
   112
                  UResourceBundle *fillIn, UErrorCode *status); 
sl@0
   113
sl@0
   114
/**
sl@0
   115
 * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside 
sl@0
   116
 * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
sl@0
   117
 * "zoneStrings/3". Keys and indexes are supported. Keys
sl@0
   118
 * need to reference data in named structures, while indexes can reference both 
sl@0
   119
 * named and anonymous resources.
sl@0
   120
 * Features a fill-in parameter. 
sl@0
   121
 *
sl@0
   122
 * @param resourceBundle    a resource
sl@0
   123
 * @param pathToResource    a path that will lead to the requested resource
sl@0
   124
 * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
sl@0
   125
 *                          Alternatively, you can supply a struct to be filled by this function.
sl@0
   126
 * @param status            fills in the outgoing error code.
sl@0
   127
 * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
sl@0
   128
 * @draft ICU 2.2
sl@0
   129
 */
sl@0
   130
U_CAPI UResourceBundle* U_EXPORT2
sl@0
   131
ures_findSubResource(const UResourceBundle *resB, 
sl@0
   132
                     char* pathToResource, 
sl@0
   133
                     UResourceBundle *fillIn, UErrorCode *status);
sl@0
   134
sl@0
   135
/**
sl@0
   136
 * Returns a functionally equivalent locale (considering keywords) for the specified keyword.
sl@0
   137
 * @param result fillin for the equivalent locale
sl@0
   138
 * @param resultCapacity capacity of the fillin buffer
sl@0
   139
 * @param path path to the tree, or NULL for ICU data
sl@0
   140
 * @param resName top level resource. Example: "collations"
sl@0
   141
 * @param keyword locale keyword. Example: "collation"
sl@0
   142
 * @param locid The requested locale
sl@0
   143
 * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the 
sl@0
   144
 * requested locale was available. The locale is defined as 'available' if it physically 
sl@0
   145
 * exists within the specified tree.
sl@0
   146
 * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE'
sl@0
   147
 * @param status error code
sl@0
   148
 * @return  the actual buffer size needed for the full locale.  If it's greater 
sl@0
   149
 * than resultCapacity, the returned full name will be truncated and an error code will be returned.
sl@0
   150
 * @internal ICU 3.0
sl@0
   151
 */
sl@0
   152
U_INTERNAL int32_t U_EXPORT2
sl@0
   153
ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, 
sl@0
   154
                             const char *path, const char *resName, const char *keyword, const char *locid,
sl@0
   155
                             UBool *isAvailable, UBool omitDefault, UErrorCode *status);
sl@0
   156
sl@0
   157
/**
sl@0
   158
 * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
sl@0
   159
 * @param path path to the tree, or NULL for ICU data
sl@0
   160
 * @param keyword a particular keyword to consider, must match a top level resource name 
sl@0
   161
 * within the tree.
sl@0
   162
 * @param status error code
sl@0
   163
 * @internal ICU 3.0
sl@0
   164
 */
sl@0
   165
U_INTERNAL UEnumeration* U_EXPORT2
sl@0
   166
ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);
sl@0
   167
sl@0
   168
#endif /*URESIMP_H*/