static void storeMappingData(){ int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; ValueStruct* value = NULL; int32_t codepoint = 0; int32_t elementCount = 0; int32_t writtenElementCount = 0; int32_t mappingLength = 1; /* minimum mapping length */ int32_t oldMappingLength = 0; uint16_t trieWord =0; int32_t limitIndex = 0; if (hashTable == NULL) { return; } elementCount = uhash_count(hashTable); /*initialize the mapping data */ mappingData = (uint16_t*) uprv_calloc(mappingDataCapacity, U_SIZEOF_UCHAR); while(writtenElementCount < elementCount){ while( (element = uhash_nextElement(hashTable, &pos))!=NULL){ codepoint = element->key.integer; value = (ValueStruct*)element->value.pointer; /* store the start of indexes */ if(oldMappingLength != mappingLength){ /* Assume that index[] is used according to the enums defined */ if(oldMappingLength <=_SPREP_MAX_INDEX_TOP_LENGTH){ indexes[_SPREP_NORM_CORRECTNS_LAST_UNI_VERSION+mappingLength] = currentIndex; } if(oldMappingLength <= _SPREP_MAX_INDEX_TOP_LENGTH && mappingLength == _SPREP_MAX_INDEX_TOP_LENGTH +1){ limitIndex = currentIndex; } oldMappingLength = mappingLength; } if(value->length == mappingLength){ uint32_t savedTrieWord = 0; trieWord = currentIndex << 2; /* turn on the 2nd bit to signal that the following bits contain an index */ trieWord += 0x02; if(trieWord > _SPREP_TYPE_THRESHOLD){ fprintf(stderr,"trieWord cannot contain value greater than 0x%04X.\n",_SPREP_TYPE_THRESHOLD); exit(U_ILLEGAL_CHAR_FOUND); } /* figure out if the code point has type already stored */ savedTrieWord= utrie_get32(sprepTrie,codepoint,NULL); if(savedTrieWord!=0){ if((savedTrieWord- _SPREP_TYPE_THRESHOLD) == USPREP_PROHIBITED){ /* turn on the first bit in trie word */ trieWord += 0x01; }else{ /* * the codepoint has value something other than prohibited * and a mapping .. error! */ fprintf(stderr,"Type for codepoint \\U%08X already set!.\n", (int)codepoint); exit(U_ILLEGAL_ARGUMENT_ERROR); } } /* now set the value in the trie */ if(!utrie_set32(sprepTrie,codepoint,trieWord)){ fprintf(stderr,"Could not set the value for code point.\n"); exit(U_ILLEGAL_ARGUMENT_ERROR); } /* written the trie word for the codepoint... increment the count*/ writtenElementCount++; /* sanity check are we exceeding the max number allowed */ if(currentIndex+value->length+1 > _SPREP_MAX_INDEX_VALUE){ fprintf(stderr, "Too many entries in the mapping table %i. Maximum allowed is %i\n", currentIndex+value->length, _SPREP_MAX_INDEX_VALUE); exit(U_INDEX_OUTOFBOUNDS_ERROR); } /* copy the mapping data */ /* write the length */ if(mappingLength > _SPREP_MAX_INDEX_TOP_LENGTH ){ /* the cast here is safe since we donot expect the length to be > 65535 */ mappingData[currentIndex++] = (uint16_t) mappingLength; } /* copy the contents to mappindData array */ uprv_memmove(mappingData+currentIndex, value->mapping, value->length*U_SIZEOF_UCHAR); currentIndex += value->length; if (currentIndex > mappingDataCapacity) { /* If this happens there is a bug in the computation of the mapping data size in storeMapping() */ fprintf(stderr, "gensprep, fatal error at %s, %d. Aborting.\n", __FILE__, __LINE__); exit(U_INTERNAL_PROGRAM_ERROR); } } } mappingLength++; pos = -1; } /* set the last length for range check */ if(mappingLength <= _SPREP_MAX_INDEX_TOP_LENGTH){ indexes[_SPREP_NORM_CORRECTNS_LAST_UNI_VERSION+mappingLength] = currentIndex+1; }else{ indexes[_SPREP_FOUR_UCHARS_MAPPING_INDEX_START] = limitIndex; } }
//-------------------------------------------------------------------------- // // Assignment Operator // //-------------------------------------------------------------------------- RegexPattern &RegexPattern::operator = (const RegexPattern &other) { if (this == &other) { // Source and destination are the same. Don't do anything. return *this; } // Clean out any previous contents of object being assigned to. zap(); // Give target object a default initialization init(); // Copy simple fields fDeferredStatus = other.fDeferredStatus; if (U_FAILURE(fDeferredStatus)) { return *this; } if (other.fPatternString == NULL) { fPatternString = NULL; fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus); } else { fPatternString = new UnicodeString(*(other.fPatternString)); if (fPatternString == NULL) { fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; } else { fPattern = utext_openConstUnicodeString(NULL, fPatternString, &fDeferredStatus); } } if (U_FAILURE(fDeferredStatus)) { return *this; } fFlags = other.fFlags; fLiteralText = other.fLiteralText; fMinMatchLen = other.fMinMatchLen; fFrameSize = other.fFrameSize; fDataSize = other.fDataSize; fStaticSets = other.fStaticSets; fStaticSets8 = other.fStaticSets8; fStartType = other.fStartType; fInitialStringIdx = other.fInitialStringIdx; fInitialStringLen = other.fInitialStringLen; *fInitialChars = *other.fInitialChars; fInitialChar = other.fInitialChar; *fInitialChars8 = *other.fInitialChars8; fNeedsAltInput = other.fNeedsAltInput; // Copy the pattern. It's just values, nothing deep to copy. fCompiledPat->assign(*other.fCompiledPat, fDeferredStatus); fGroupMap->assign(*other.fGroupMap, fDeferredStatus); // Copy the Unicode Sets. // Could be made more efficient if the sets were reference counted and shared, // but I doubt that pattern copying will be particularly common. // Note: init() already added an empty element zero to fSets int32_t i; int32_t numSets = other.fSets->size(); fSets8 = new Regex8BitSet[numSets]; if (fSets8 == NULL) { fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; return *this; } for (i=1; i<numSets; i++) { if (U_FAILURE(fDeferredStatus)) { return *this; } UnicodeSet *sourceSet = (UnicodeSet *)other.fSets->elementAt(i); UnicodeSet *newSet = new UnicodeSet(*sourceSet); if (newSet == NULL) { fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; break; } fSets->addElement(newSet, fDeferredStatus); fSets8[i] = other.fSets8[i]; } // Copy the named capture group hash map. int32_t hashPos = UHASH_FIRST; while (const UHashElement *hashEl = uhash_nextElement(other.fNamedCaptureMap, &hashPos)) { if (U_FAILURE(fDeferredStatus)) { break; } const UnicodeString *name = (const UnicodeString *)hashEl->key.pointer; UnicodeString *key = new UnicodeString(*name); int32_t val = hashEl->value.integer; if (key == NULL) { fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; } else { uhash_puti(fNamedCaptureMap, key, val, &fDeferredStatus); } } return *this; }