// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * * Copyright (C) 2003-2016, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: usprep.cpp * encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * * created on: 2003jul2 * created by: Ram Viswanadha */ #include "unicode/utypes.h" #if !UCONFIG_NO_IDNA #include "unicode/usprep.h" #include "unicode/normalizer2.h" #include "unicode/ustring.h" #include "unicode/uchar.h" #include "unicode/uversion.h" #include "umutex.h" #include "cmemory.h" #include "sprpimpl.h" #include "ustr_imp.h" #include "uhash.h" #include "cstring.h" #include "udataswp.h" #include "ucln_cmn.h" #include "ubidi_props.h" #include "uprops.h" U_NAMESPACE_USE U_CDECL_BEGIN /* Static cache for already opened StringPrep profiles */ static UHashtable *SHARED_DATA_HASHTABLE = …; static icu::UInitOnce gSharedDataInitOnce { … }; static UMutex usprepMutex; /* format version of spp file */ //static uint8_t formatVersion[4]={ 0, 0, 0, 0 }; /* the Unicode version of the sprep data */ static UVersionInfo dataVersion= …; /* Profile names must be aligned to UStringPrepProfileType */ static const char * const PROFILE_NAMES[] = …; static UBool U_CALLCONV isSPrepAcceptable(void * /* context */, const char * /* type */, const char * /* name */, const UDataInfo *pInfo) { … } static int32_t U_CALLCONV getSPrepFoldingOffset(uint32_t data) { … } /* hashes an entry */ static int32_t U_CALLCONV hashEntry(const UHashTok parm) { … } /* compares two entries */ static UBool U_CALLCONV compareEntries(const UHashTok p1, const UHashTok p2) { … } static void usprep_unload(UStringPrepProfile* data){ … } static int32_t usprep_internal_flushCache(UBool noRefCount){ … } /* Works just like ucnv_flushCache() static int32_t usprep_flushCache(){ return usprep_internal_flushCache(false); } */ static UBool U_CALLCONV usprep_cleanup(){ … } U_CDECL_END /** Initializes the cache for resources */ static void U_CALLCONV createCache(UErrorCode &status) { … } static void initCache(UErrorCode *status) { … } static UBool U_CALLCONV loadData(UStringPrepProfile* profile, const char* path, const char* name, const char* type, UErrorCode* errorCode) { … } static UStringPrepProfile* usprep_getProfile(const char* path, const char* name, UErrorCode *status){ … } U_CAPI UStringPrepProfile* U_EXPORT2 usprep_open(const char* path, const char* name, UErrorCode* status){ … } U_CAPI UStringPrepProfile* U_EXPORT2 usprep_openByType(UStringPrepProfileType type, UErrorCode* status) { … } U_CAPI void U_EXPORT2 usprep_close(UStringPrepProfile* profile){ … } U_CFUNC void uprv_syntaxError(const char16_t* rules, int32_t pos, int32_t rulesLen, UParseError* parseError){ … } static inline UStringPrepType getValues(uint16_t trieWord, int16_t& value, UBool& isIndex){ … } // TODO: change to writing to UnicodeString not char16_t * static int32_t usprep_map( const UStringPrepProfile* profile, const char16_t* src, int32_t srcLength, char16_t* dest, int32_t destCapacity, int32_t options, UParseError* parseError, UErrorCode* status ){ … } /* 1) Map -- For each character in the input, check if it has a mapping and, if so, replace it with its mapping. 2) Normalize -- Possibly normalize the result of step 1 using Unicode normalization. 3) Prohibit -- Check for any characters that are not allowed in the output. If any are found, return an error. 4) Check bidi -- Possibly check for right-to-left characters, and if any are found, make sure that the whole string satisfies the requirements for bidirectional strings. If the string does not satisfy the requirements for bidirectional strings, return an error. [Unicode3.2] defines several bidirectional categories; each character has one bidirectional category assigned to it. For the purposes of the requirements below, an "RandALCat character" is a character that has Unicode bidirectional categories "R" or "AL"; an "LCat character" is a character that has Unicode bidirectional category "L". Note that there are many characters which fall in neither of the above definitions; Latin digits (<U+0030> through <U+0039>) are examples of this because they have bidirectional category "EN". In any profile that specifies bidirectional character handling, all three of the following requirements MUST be met: 1) The characters in section 5.8 MUST be prohibited. 2) If a string contains any RandALCat character, the string MUST NOT contain any LCat character. 3) If a string contains any RandALCat character, a RandALCat character MUST be the first character of the string, and a RandALCat character MUST be the last character of the string. */ U_CAPI int32_t U_EXPORT2 usprep_prepare( const UStringPrepProfile* profile, const char16_t* src, int32_t srcLength, char16_t* dest, int32_t destCapacity, int32_t options, UParseError* parseError, UErrorCode* status ){ … } /* data swapping ------------------------------------------------------------ */ U_CAPI int32_t U_EXPORT2 usprep_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData, UErrorCode *pErrorCode) { … } #endif /* #if !UCONFIG_NO_IDNA */