os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/usprep.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  *******************************************************************************
     3  *
     4  *   Copyright (C) 2003-2005, International Business Machines
     5  *   Corporation and others.  All Rights Reserved.
     6  *
     7  *******************************************************************************
     8  *   file name:  usprep.h
     9  *   encoding:   US-ASCII
    10  *   tab size:   8 (not used)
    11  *   indentation:4
    12  *
    13  *   created on: 2003jul2
    14  *   created by: Ram Viswanadha
    15  */
    16 
    17 #ifndef __USPREP_H__
    18 #define __USPREP_H__
    19 
    20 /**
    21  * \file 
    22  * \brief C API: Implements the StringPrep algorithm.
    23  */
    24 
    25 #include "unicode/utypes.h"
    26 /**
    27  *
    28  * StringPrep API implements the StingPrep framework as described by RFC 3454.
    29  * StringPrep prepares Unicode strings for use in network protocols.
    30  * Profiles of StingPrep are set of rules and data according to with the
    31  * Unicode Strings are prepared. Each profiles contains tables which describe
    32  * how a code point should be treated. The tables are broadly classied into
    33  * <ul>
    34  *     <li> Unassinged Table: Contains code points that are unassigned 
    35  *          in the Unicode Version supported by StringPrep. Currently 
    36  *          RFC 3454 supports Unicode 3.2. </li>
    37  *     <li> Prohibited Table: Contains code points that are prohibted from
    38  *          the output of the StringPrep processing function. </li>
    39  *     <li> Mapping Table: Contains code ponts that are deleted from the output or case mapped. </li>
    40  * </ul>
    41  * 
    42  * The procedure for preparing Unicode strings:
    43  * <ol>
    44  *      <li> Map: For each character in the input, check if it has a mapping
    45  *           and, if so, replace it with its mapping. </li>
    46  *      <li> Normalize: Possibly normalize the result of step 1 using Unicode
    47  *           normalization. </li>
    48  *      <li> Prohibit: Check for any characters that are not allowed in the
    49  *        output.  If any are found, return an error.</li>
    50  *      <li> Check bidi: Possibly check for right-to-left characters, and if
    51  *           any are found, make sure that the whole string satisfies the
    52  *           requirements for bidirectional strings.  If the string does not
    53  *           satisfy the requirements for bidirectional strings, return an
    54  *           error.  </li>
    55  * </ol>
    56  * @author Ram Viswanadha
    57  */
    58 #if !UCONFIG_NO_IDNA
    59 
    60 #include "unicode/parseerr.h"
    61 
    62 #ifndef U_HIDE_DRAFT_API
    63 
    64 /**
    65  * The StringPrep profile
    66  * @stable ICU 2.8
    67  */
    68 typedef struct UStringPrepProfile UStringPrepProfile;
    69 
    70 
    71 /** 
    72  * Option to prohibit processing of unassigned code points in the input
    73  * 
    74  * @see  usprep_prepare
    75  * @stable ICU 2.8
    76  */
    77 #define USPREP_DEFAULT 0x0000
    78 
    79 /** 
    80  * Option to allow processing of unassigned code points in the input
    81  * 
    82  * @see  usprep_prepare
    83  * @stable ICU 2.8
    84  */
    85 #define USPREP_ALLOW_UNASSIGNED 0x0001
    86 
    87 
    88 #endif /*U_HIDE_DRAFT_API*/
    89 
    90 /**
    91  * Creates a StringPrep profile from the data file.
    92  *
    93  * @param path      string containing the full path pointing to the directory
    94  *                  where the profile reside followed by the package name
    95  *                  e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system.
    96  *                  if NULL, ICU default data files will be used.
    97  * @param fileName  name of the profile file to be opened
    98  * @param status    ICU error code in/out parameter. Must not be NULL.
    99  *                  Must fulfill U_SUCCESS before the function call.
   100  * @return Pointer to UStringPrepProfile that is opened. Should be closed by
   101  * calling usprep_close()
   102  * @see usprep_close()
   103  * @stable ICU 2.8
   104  */
   105 U_STABLE UStringPrepProfile* U_EXPORT2
   106 usprep_open(const char* path, 
   107             const char* fileName,
   108             UErrorCode* status);
   109 
   110 
   111 /**
   112  * Closes the profile
   113  * @param profile The profile to close
   114  * @stable ICU 2.8
   115  */
   116 U_STABLE void U_EXPORT2
   117 usprep_close(UStringPrepProfile* profile);
   118 
   119 
   120 /**
   121  * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
   122  * checks for prohited and BiDi characters in the order defined by RFC 3454
   123  * depending on the options specified in the profile.
   124  *
   125  * @param prep          The profile to use 
   126  * @param src           Pointer to UChar buffer containing the string to prepare
   127  * @param srcLength     Number of characters in the source string
   128  * @param dest          Pointer to the destination buffer to receive the output
   129  * @param destCapacity  The capacity of destination array
   130  * @param options       A bit set of options:
   131  *
   132  *  - USPREP_NONE               Prohibit processing of unassigned code points in the input
   133  *
   134  *  - USPREP_ALLOW_UNASSIGNED   Treat the unassigned code points are in the input 
   135  *                              as normal Unicode code points.
   136  *
   137  * @param parseError        Pointer to UParseError struct to receive information on position 
   138  *                          of error if an error is encountered. Can be NULL.
   139  * @param status            ICU in/out error code parameter.
   140  *                          U_INVALID_CHAR_FOUND if src contains
   141  *                          unmatched single surrogates.
   142  *                          U_INDEX_OUTOFBOUNDS_ERROR if src contains
   143  *                          too many code points.
   144  *                          U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
   145  * @return The number of UChars in the destination buffer
   146  * @stable ICU 2.8
   147  */
   148 
   149 U_STABLE int32_t U_EXPORT2
   150 usprep_prepare(   const UStringPrepProfile* prep,
   151                   const UChar* src, int32_t srcLength, 
   152                   UChar* dest, int32_t destCapacity,
   153                   int32_t options,
   154                   UParseError* parseError,
   155                   UErrorCode* status );
   156 
   157 
   158 #endif /* #if !UCONFIG_NO_IDNA */
   159 
   160 #endif