// package private methods ----------------------------------------- /// <summary> /// Internal constructor for builder use /// </summary> /// /// <param name="index">the index array to be slotted into this trie</param> /// <param name="data">the data array to be slotted into this trie</param> /// <param name="initialvalue">the initial value for this trie</param> /// <param name="options">trie options to use</param> /// <param name="datamanipulate">folding implementation</param> internal IntTrie(char[] index, int[] data, int initialvalue, int options, Trie.DataManipulate datamanipulate) : base(index, options, datamanipulate) { m_data_ = data; m_dataLength_ = m_data_.Length; m_initialValue_ = initialvalue; }
// protected constructor ------------------------------------------- /// <summary> /// Trie constructor for CharTrie use. /// </summary> /// /// <param name="inputStream">ICU data file input stream which contains the trie</param> /// <param name="dataManipulate">object containing the information to parse the trie data</param> /// <exception cref="IOException">thrown when input stream does not have the right header.</exception> /// @draft 2.1 protected internal Trie(DataInputStream inputStream, Trie.DataManipulate dataManipulate) { DataInputStream input = inputStream; // new DataInputStream(inputStream); // Magic number to authenticate the data. int signature = input.ReadInt(); m_options_ = input.ReadInt(); if (!CheckHeader(signature)) { throw new ArgumentException( "ICU data file error: Trie header authentication failed, please check if you have the most updated ICU data file"); } if (dataManipulate != null) { m_dataManipulate_ = dataManipulate; } else { m_dataManipulate_ = new Trie.DefaultGetFoldingOffset(); } m_isLatin1Linear_ = (m_options_ & HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_) != 0; m_dataOffset_ = input.ReadInt(); m_dataLength_ = input.ReadInt(); Unserialize(inputStream); }
// public constructors --------------------------------------------- /// <summary> /// <p> /// Creates a new Trie with the settings for the trie data. /// </p> /// <p> /// Unserialize the 32-bit-aligned input stream and use the data for the /// trie. /// </p> /// </summary> /// /// <param name="inputStream">file input stream to a ICU data file, containing the trie</param> /// <param name="dataManipulate">object which provides methods to parse the char data</param> /// <exception cref="IOException">thrown when data reading fails</exception> /// @draft 2.1 public IntTrie(DataInputStream inputStream, Trie.DataManipulate dataManipulate) : base(inputStream, dataManipulate) { if (!IsIntTrie()) { throw new ArgumentException( "Data given does not belong to a int trie."); } }
// public constructors --------------------------------------------- /// <summary> /// <p> /// Creates a new Trie with the settings for the trie data. /// </p> /// <p> /// Unserialize the 32-bit-aligned input stream and use the data for the /// trie. /// </p> /// </summary> /// /// <param name="inputStream">file input stream to a ICU data file, containing the trie</param> /// <param name="dataManipulate">object which provides methods to parse the char data</param> /// <exception cref="IOException">thrown when data reading fails</exception> /// @draft 2.1 public CharTrie(DataInputStream inputStream, Trie.DataManipulate dataManipulate) : base(inputStream, dataManipulate) { if (!IsCharTrie()) { throw new ArgumentException( "Data given does not belong to a char trie."); } m_friendAgent_ = new CharTrie.FriendAgent(this); }
/// <summary> /// Make a dummy CharTrie. A dummy trie is an empty runtime trie, used when a /// real data trie cannot be loaded. /// The trie always returns the initialValue, or the leadUnitValue for lead /// surrogate code points. The Latin-1 part is always set up to be linear. /// </summary> /// /// <param name="initialValue">the initial value that is set for all code points</param> /// <param name="leadUnitValue">the value for lead surrogate code _units_ that do not haveassociated supplementary data</param> /// <param name="dataManipulate">object which provides methods to parse the char data</param> public CharTrie(int initialValue, int leadUnitValue, Trie.DataManipulate dataManipulate) : base(new char[IBM.ICU.Impl.Trie.BMP_INDEX_LENGTH + IBM.ICU.Impl.Trie.SURROGATE_BLOCK_COUNT], IBM.ICU.Impl.Trie.HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_, dataManipulate) { int dataLength, latin1Length, i, limit; char block; /* calculate the actual size of the dummy trie data */ /* max(Latin-1, block 0) */ dataLength = latin1Length = (IBM.ICU.Impl.Trie.INDEX_STAGE_1_SHIFT_ <= 8) ? 256 : IBM.ICU.Impl.Trie.DATA_BLOCK_LENGTH; if (leadUnitValue != initialValue) { dataLength += IBM.ICU.Impl.Trie.DATA_BLOCK_LENGTH; } m_data_ = new char[dataLength]; m_dataLength_ = dataLength; m_initialValue_ = (char)initialValue; /* fill the index and data arrays */ /* indexes are preset to 0 (block 0) */ /* Latin-1 data */ for (i = 0; i < latin1Length; ++i) { m_data_[i] = (char)initialValue; } if (leadUnitValue != initialValue) { /* indexes for lead surrogate code units to the block after Latin-1 */ block = (char)(latin1Length >> IBM.ICU.Impl.Trie.INDEX_STAGE_2_SHIFT_); i = 0xd800 >> IBM.ICU.Impl.Trie.INDEX_STAGE_1_SHIFT_; limit = 0xdc00 >> IBM.ICU.Impl.Trie.INDEX_STAGE_1_SHIFT_; for (; i < limit; ++i) { m_index_[i] = block; } /* data for lead surrogate code units */ limit = latin1Length + IBM.ICU.Impl.Trie.DATA_BLOCK_LENGTH; for (i = latin1Length; i < limit; ++i) { m_data_[i] = (char)leadUnitValue; } } m_friendAgent_ = new CharTrie.FriendAgent(this); }
/// <summary> /// Trie constructor /// </summary> /// /// <param name="index">array to be used for index</param> /// <param name="options">used by the trie</param> /// <param name="dataManipulate">object containing the information to parse the trie data</param> /// @draft 2.2 protected internal Trie(char[] index, int options, Trie.DataManipulate dataManipulate) { m_options_ = options; if (dataManipulate != null) { m_dataManipulate_ = dataManipulate; } else { m_dataManipulate_ = new Trie.DefaultGetFoldingOffset(); } m_isLatin1Linear_ = (m_options_ & HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_) != 0; m_index_ = index; m_dataOffset_ = m_index_.Length; }
/// <summary> /// Serializes the build table with 32 bit data /// </summary> /// /// <param name="datamanipulate">builder raw fold method implementation</param> /// <param name="triedatamanipulate">result trie fold method</param> /// <returns>a new trie</returns> public IntTrie Serialize(TrieBuilder.DataManipulate datamanipulate, Trie.DataManipulate triedatamanipulate) { if (datamanipulate == null) { throw new ArgumentException("Parameters can not be null"); } // fold and compact if necessary, also checks that indexLength is // within limits if (!m_isCompacted_) { // compact once without overlap to improve folding Compact(false); // fold the supplementary part of the index array Fold(datamanipulate); // compact again with overlap for minimum data array length Compact(true); m_isCompacted_ = true; } // is dataLength within limits? if (m_dataLength_ >= IBM.ICU.Impl.TrieBuilder.MAX_DATA_LENGTH_) { throw new IndexOutOfRangeException("Data length too small".ToString()); } char[] index = new char[m_indexLength_]; int[] data = new int[m_dataLength_]; // write the index (stage 1) array and the 32-bit data (stage 2) array // write 16-bit index values shifted right by INDEX_SHIFT_ for (int i = 0; i < m_indexLength_; i++) { index[i] = (char)((int)(((uint)m_index_[i]) >> IBM.ICU.Impl.TrieBuilder.INDEX_SHIFT_)); } // write 32-bit data values System.Array.Copy((Array)(m_data_), 0, (Array)(data), 0, m_dataLength_); int options = IBM.ICU.Impl.TrieBuilder.SHIFT_ | (IBM.ICU.Impl.TrieBuilder.INDEX_SHIFT_ << IBM.ICU.Impl.TrieBuilder.OPTIONS_INDEX_SHIFT_); options |= IBM.ICU.Impl.TrieBuilder.OPTIONS_DATA_IS_32_BIT_; if (m_isLatin1Linear_) { options |= IBM.ICU.Impl.TrieBuilder.OPTIONS_LATIN1_IS_LINEAR_; } return(new IntTrie(index, data, m_initialValue_, options, triedatamanipulate)); }