sl@0: /*
sl@0: *******************************************************************************
sl@0: *
sl@0: * Copyright (C) 2003-2005, International Business Machines
sl@0: * Corporation and others. All Rights Reserved.
sl@0: *
sl@0: *******************************************************************************
sl@0: * file name: usprep.h
sl@0: * encoding: US-ASCII
sl@0: * tab size: 8 (not used)
sl@0: * indentation:4
sl@0: *
sl@0: * created on: 2003jul2
sl@0: * created by: Ram Viswanadha
sl@0: */
sl@0:
sl@0: #ifndef __USPREP_H__
sl@0: #define __USPREP_H__
sl@0:
sl@0: /**
sl@0: * \file
sl@0: * \brief C API: Implements the StringPrep algorithm.
sl@0: */
sl@0:
sl@0: #include "unicode/utypes.h"
sl@0: /**
sl@0: *
sl@0: * StringPrep API implements the StingPrep framework as described by RFC 3454.
sl@0: * StringPrep prepares Unicode strings for use in network protocols.
sl@0: * Profiles of StingPrep are set of rules and data according to with the
sl@0: * Unicode Strings are prepared. Each profiles contains tables which describe
sl@0: * how a code point should be treated. The tables are broadly classied into
sl@0: *
sl@0: * - Unassinged Table: Contains code points that are unassigned
sl@0: * in the Unicode Version supported by StringPrep. Currently
sl@0: * RFC 3454 supports Unicode 3.2.
sl@0: * - Prohibited Table: Contains code points that are prohibted from
sl@0: * the output of the StringPrep processing function.
sl@0: * - Mapping Table: Contains code ponts that are deleted from the output or case mapped.
sl@0: *
sl@0: *
sl@0: * The procedure for preparing Unicode strings:
sl@0: *
sl@0: * - Map: For each character in the input, check if it has a mapping
sl@0: * and, if so, replace it with its mapping.
sl@0: * - Normalize: Possibly normalize the result of step 1 using Unicode
sl@0: * normalization.
sl@0: * - Prohibit: Check for any characters that are not allowed in the
sl@0: * output. If any are found, return an error.
sl@0: * - Check bidi: Possibly check for right-to-left characters, and if
sl@0: * any are found, make sure that the whole string satisfies the
sl@0: * requirements for bidirectional strings. If the string does not
sl@0: * satisfy the requirements for bidirectional strings, return an
sl@0: * error.
sl@0: *
sl@0: * @author Ram Viswanadha
sl@0: */
sl@0: #if !UCONFIG_NO_IDNA
sl@0:
sl@0: #include "unicode/parseerr.h"
sl@0:
sl@0: #ifndef U_HIDE_DRAFT_API
sl@0:
sl@0: /**
sl@0: * The StringPrep profile
sl@0: * @stable ICU 2.8
sl@0: */
sl@0: typedef struct UStringPrepProfile UStringPrepProfile;
sl@0:
sl@0:
sl@0: /**
sl@0: * Option to prohibit processing of unassigned code points in the input
sl@0: *
sl@0: * @see usprep_prepare
sl@0: * @stable ICU 2.8
sl@0: */
sl@0: #define USPREP_DEFAULT 0x0000
sl@0:
sl@0: /**
sl@0: * Option to allow processing of unassigned code points in the input
sl@0: *
sl@0: * @see usprep_prepare
sl@0: * @stable ICU 2.8
sl@0: */
sl@0: #define USPREP_ALLOW_UNASSIGNED 0x0001
sl@0:
sl@0:
sl@0: #endif /*U_HIDE_DRAFT_API*/
sl@0:
sl@0: /**
sl@0: * Creates a StringPrep profile from the data file.
sl@0: *
sl@0: * @param path string containing the full path pointing to the directory
sl@0: * where the profile reside followed by the package name
sl@0: * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system.
sl@0: * if NULL, ICU default data files will be used.
sl@0: * @param fileName name of the profile file to be opened
sl@0: * @param status ICU error code in/out parameter. Must not be NULL.
sl@0: * Must fulfill U_SUCCESS before the function call.
sl@0: * @return Pointer to UStringPrepProfile that is opened. Should be closed by
sl@0: * calling usprep_close()
sl@0: * @see usprep_close()
sl@0: * @stable ICU 2.8
sl@0: */
sl@0: U_STABLE UStringPrepProfile* U_EXPORT2
sl@0: usprep_open(const char* path,
sl@0: const char* fileName,
sl@0: UErrorCode* status);
sl@0:
sl@0:
sl@0: /**
sl@0: * Closes the profile
sl@0: * @param profile The profile to close
sl@0: * @stable ICU 2.8
sl@0: */
sl@0: U_STABLE void U_EXPORT2
sl@0: usprep_close(UStringPrepProfile* profile);
sl@0:
sl@0:
sl@0: /**
sl@0: * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
sl@0: * checks for prohited and BiDi characters in the order defined by RFC 3454
sl@0: * depending on the options specified in the profile.
sl@0: *
sl@0: * @param prep The profile to use
sl@0: * @param src Pointer to UChar buffer containing the string to prepare
sl@0: * @param srcLength Number of characters in the source string
sl@0: * @param dest Pointer to the destination buffer to receive the output
sl@0: * @param destCapacity The capacity of destination array
sl@0: * @param options A bit set of options:
sl@0: *
sl@0: * - USPREP_NONE Prohibit processing of unassigned code points in the input
sl@0: *
sl@0: * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input
sl@0: * as normal Unicode code points.
sl@0: *
sl@0: * @param parseError Pointer to UParseError struct to receive information on position
sl@0: * of error if an error is encountered. Can be NULL.
sl@0: * @param status ICU in/out error code parameter.
sl@0: * U_INVALID_CHAR_FOUND if src contains
sl@0: * unmatched single surrogates.
sl@0: * U_INDEX_OUTOFBOUNDS_ERROR if src contains
sl@0: * too many code points.
sl@0: * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
sl@0: * @return The number of UChars in the destination buffer
sl@0: * @stable ICU 2.8
sl@0: */
sl@0:
sl@0: U_STABLE int32_t U_EXPORT2
sl@0: usprep_prepare( const UStringPrepProfile* prep,
sl@0: const UChar* src, int32_t srcLength,
sl@0: UChar* dest, int32_t destCapacity,
sl@0: int32_t options,
sl@0: UParseError* parseError,
sl@0: UErrorCode* status );
sl@0:
sl@0:
sl@0: #endif /* #if !UCONFIG_NO_IDNA */
sl@0:
sl@0: #endif