]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/sprpimpl.h
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / common / sprpimpl.h
index c545fe3e98a07904d16f165999c48612be13a2f3..ca0bcdb51695cc756aa4e36f73cb48f1477bd207 100644 (file)
@@ -1,12 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
  *******************************************************************************
  *
- *   Copyright (C) 2003, International Business Machines
+ *   Copyright (C) 2003-2006, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *
  *******************************************************************************
  *   file name:  sprpimpl.h
- *   encoding:   US-ASCII
+ *   encoding:   UTF-8
  *   tab size:   8 (not used)
  *   indentation:4
  *
 #define SPRPIMPL_H
 
 #include "unicode/utypes.h"
+
+#if !UCONFIG_NO_IDNA
+
 #include "unicode/ustring.h"
 #include "unicode/parseerr.h"
+#include "unicode/usprep.h"
+#include "unicode/udata.h"
+#include "utrie.h"
+#include "udataswp.h"
+#include "ubidi_props.h"
 
-#if !UCONFIG_NO_IDNA
+#define _SPREP_DATA_TYPE "spp"
+
+enum UStringPrepType{
+    USPREP_UNASSIGNED           = 0x0000 ,
+    USPREP_MAP                  = 0x0001 ,
+    USPREP_PROHIBITED           = 0x0002 , 
+    USPREP_DELETE               = 0x0003 ,
+    USPREP_TYPE_LIMIT           = 0x0004  
+};
+
+typedef enum UStringPrepType UStringPrepType;
+
+#ifdef USPREP_TYPE_NAMES_ARRAY
+static const char* usprepTypeNames[] ={
+    "UNASSIGNED" ,          
+    "MAP" , 
+    "PROHIBITED" ,        
+    "DELETE",
+    "TYPE_LIMIT" 
+};
+#endif
 
 enum{
-    UIDNA_NO_VALUE          = 0x0000 ,
-    UIDNA_UNASSIGNED        = 0x0001 , 
-    UIDNA_PROHIBITED        = 0x0002 , 
-    UIDNA_MAP_NFKC          = 0x0003 , 
-    UIDNA_LABEL_SEPARATOR   = 0x0004 
+    _SPREP_NORMALIZATION_ON = 0x0001,
+    _SPREP_CHECK_BIDI_ON    = 0x0002
 };
+
 enum{
-    _IDNA_LENGTH_IN_MAPPING_TABLE = 0x0003 /*11*/
+    _SPREP_TYPE_THRESHOLD       = 0xFFF0,
+    _SPREP_MAX_INDEX_VALUE      = 0x3FBF,   /*16139*/ 
+    _SPREP_MAX_INDEX_TOP_LENGTH = 0x0003
 };
+
 /* indexes[] value names */
 enum {
-    _IDNA_INDEX_TRIE_SIZE,             /* number of bytes in normalization trie */
-    _IDNA_INDEX_MAPPING_DATA_SIZE,     /* The array that contains the mapping   */
-    _IDNA_INDEX_TOP=3                  /* changing this requires a new formatVersion */
+    _SPREP_INDEX_TRIE_SIZE                  = 0, /* number of bytes in StringPrep trie */
+    _SPREP_INDEX_MAPPING_DATA_SIZE          = 1, /* The array that contains the mapping   */
+    _SPREP_NORM_CORRECTNS_LAST_UNI_VERSION  = 2, /* The index of Unicode version of last entry in NormalizationCorrections.txt */ 
+    _SPREP_ONE_UCHAR_MAPPING_INDEX_START    = 3, /* The starting index of 1 UChar mapping index in the mapping data array */
+    _SPREP_TWO_UCHARS_MAPPING_INDEX_START   = 4, /* The starting index of 2 UChars mapping index in the mapping data array */
+    _SPREP_THREE_UCHARS_MAPPING_INDEX_START = 5, /* The starting index of 3 UChars mapping index in the mapping data array */
+    _SPREP_FOUR_UCHARS_MAPPING_INDEX_START  = 6, /* The starting index of 4 UChars mapping index in the mapping data array */
+    _SPREP_OPTIONS                          = 7, /* Bit set of options to turn on in the profile */
+    _SPREP_INDEX_TOP=16                          /* changing this requires a new formatVersion */
 };
 
-enum {
-    _IDNA_MAPPING_DATA_SIZE = 2000,
-    _IDNA_MAP_TO_NOTHING = 0x7FF
+typedef struct UStringPrepKey UStringPrepKey;
+
+
+struct UStringPrepKey{
+    char* name;
+    char* path;
+};
+
+struct UStringPrepProfile{
+    int32_t indexes[_SPREP_INDEX_TOP];
+    UTrie sprepTrie;
+    const uint16_t* mappingData;
+    UDataMemory* sprepData;
+    int32_t refCount;
+    UBool isDataLoaded;
+    UBool doNFKC;
+    UBool checkBiDi;
 };
 
-#if defined(XP_CPLUSPLUS)
-static inline 
-void uprv_syntaxError(const UChar* rules, 
+/**
+ * Helper function for populating the UParseError struct
+ * @internal
+ */
+U_CAPI void U_EXPORT2
+uprv_syntaxError(const UChar* rules, 
                  int32_t pos,
                  int32_t rulesLen,
-                 UParseError* parseError)
-{
-    if(parseError == NULL){
-        return;
-    }
-    if(pos == rulesLen && rulesLen >0){
-        pos--;
-    }
-    parseError->offset = pos;
-    parseError->line = 0 ; // we are not using line numbers 
-    
-    // for pre-context
-    int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1));
-    int32_t stop  = pos;
-    
-    u_memcpy(parseError->preContext,rules+start,stop-start);
-    //null terminate the buffer
-    parseError->preContext[stop-start] = 0;
-    
-    //for post-context
-    start = pos;
-    if(start<rulesLen) {
-        U16_FWD_1(rules, start, rulesLen);
-    }
-
-    stop  = ((pos+U_PARSE_CONTEXT_LEN)<= rulesLen )? (pos+(U_PARSE_CONTEXT_LEN)) : 
-                                                            rulesLen;
-    if(start < stop){
-        u_memcpy(parseError->postContext,rules+start,stop-start);
-        //null terminate the buffer
-        parseError->postContext[stop-start]= 0;
-    }
-    
-}
-#endif
+                 UParseError* parseError);
 
-/* error codes for prototyping 
-#define U_IDNA_ERROR_START                      U_ERROR_LIMIT
-#define U_IDNA_PROHIBITED_CODEPOINT_FOUND_ERROR ((UErrorCode)(U_IDNA_ERROR_START + 1))
-#define U_IDNA_UNASSIGNED_CODEPOINT_FOUND_ERROR ((UErrorCode)(U_IDNA_ERROR_START + 2))
-#define U_IDNA_CHECK_BIDI_ERROR                 ((UErrorCode)(U_IDNA_ERROR_START + 3))
-#define U_IDNA_STD3_ASCII_RULES_ERROR           ((UErrorCode)(U_IDNA_ERROR_START + 4))
-#define U_IDNA_ACE_PREFIX_ERROR                 ((UErrorCode)(U_IDNA_ERROR_START + 5))
-#define U_IDNA_VERIFICATION_ERROR               ((UErrorCode)(U_IDNA_ERROR_START + 6))
-#define U_IDNA_LABEL_TOO_LONG_ERROR                  ((UErrorCode)(U_IDNA_ERROR_START + 8))   
-*/
+
+/**
+ * Swap StringPrep .spp profile data. See udataswp.h.
+ * @internal
+ */
+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 */