Exemplo n.º 1
0
        // private methods --------------------------------------------------

        /// <summary>
        /// Group name iteration, iterate all the names in the current 32-group and
        /// returns the first codepoint that has a valid name.
        /// </summary>
        /// <param name="result">Stores the result codepoint and name.</param>
        /// <param name="limit">Last codepoint + 1 in range to search.</param>
        /// <returns>false if a codepoint with a name is found in group and we can
        /// bail from further iteration, true to continue on with the
        /// iteration.</returns>
        private bool IterateSingleGroup(ValueEnumeratorElement result, int limit)
        {
            lock (GROUP_OFFSETS_)
            {
                lock (GROUP_LENGTHS_)
                {
                    int index = m_name_.GetGroupLengths(m_groupIndex_, GROUP_OFFSETS_,
                                                        GROUP_LENGTHS_);
                    while (m_current_ < limit)
                    {
                        int    offset = UCharacterName.GetGroupOffset(m_current_);
                        string name   = m_name_.GetGroupName(
                            index + GROUP_OFFSETS_[offset],
                            GROUP_LENGTHS_[offset], (UCharacterNameChoice)m_choice_);
                        if ((name == null || name.Length == 0) &&
                            m_choice_ == (int)UCharacterNameChoice.ExtendedCharName)
                        {
                            name = m_name_.GetExtendedName(m_current_);
                        }
                        if (name != null && name.Length > 0)
                        {
                            result.Integer = m_current_;
                            result.Value   = name;
                            return(false);
                        }
                        ++m_current_;
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        // private methods --------------------------------------------------

        /// <summary>
        /// Group name iteration, iterate all the names in the current 32-group and
        /// returns the first codepoint that has a valid name.
        /// </summary>
        /// <param name="result">Stores the result codepoint and name.</param>
        /// <param name="limit">Last codepoint + 1 in range to search.</param>
        /// <returns>false if a codepoint with a name is found in group and we can
        /// bail from further iteration, true to continue on with the
        /// iteration.</returns>
        private bool IterateSingleGroup(ValueEnumeratorElement result, int limit)
        {
            lock (GROUP_OFFSETS_) // ICU4N: Removed unnecessary redundant lock
            {
                int index = m_name_.GetGroupLengths(m_groupIndex_, GROUP_OFFSETS_,
                                                    GROUP_LENGTHS_);
                while (m_current_ < limit)
                {
                    int    offset = UCharacterName.GetGroupOffset(m_current_);
                    string name   = m_name_.GetGroupName(
                        index + GROUP_OFFSETS_[offset],
                        GROUP_LENGTHS_[offset], (UCharacterNameChoice)m_choice_);
                    if (string.IsNullOrEmpty(name) &&
                        m_choice_ == (int)UCharacterNameChoice.ExtendedCharName)
                    {
                        name = m_name_.GetExtendedName(m_current_);
                    }
                    if (!string.IsNullOrEmpty(name))
                    {
                        result.Integer = m_current_;
                        result.Value   = name;
                        return(false);
                    }
                    ++m_current_;
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Group name iteration, iterate all the names in the current 32-group and
        /// returns the first codepoint that has a valid name.
        /// </summary>
        /// <param name="result">Stores the result codepoint and name.</param>
        /// <param name="limit">Last codepoint + 1 in range to search.</param>
        /// <returns>false if a codepoint with a name is found in group and we can
        /// bail from further iteration, true to continue on with the
        /// iteration.</returns>
        private bool IterateGroup(ValueEnumeratorElement result, int limit)
        {
            if (m_groupIndex_ < 0)
            {
                m_groupIndex_ = m_name_.GetGroup(m_current_);
            }

            while (m_groupIndex_ < m_name_.m_groupcount_ &&
                   m_current_ < limit)
            {
                // iterate till the last group or the last codepoint
                int startMSB = UCharacterName.GetCodepointMSB(m_current_);
                int gMSB     = m_name_.GetGroupMSB(m_groupIndex_); // can be -1
                if (startMSB == gMSB)
                {
                    if (startMSB == UCharacterName.GetCodepointMSB(limit - 1))
                    {
                        // if start and limit - 1 are in the same group, then enumerate
                        // only in that one
                        return(IterateSingleGroup(result, limit));
                    }
                    // enumerate characters in the partial start group
                    // if (m_name_.getGroupOffset(m_current_) != 0) {
                    if (!IterateSingleGroup(result,
                                            UCharacterName.GetGroupLimit(gMSB)))
                    {
                        return(false);
                    }
                    ++m_groupIndex_; // continue with the next group
                }
                else if (startMSB > gMSB)
                {
                    // make sure that we start enumerating with the first group
                    // after start
                    m_groupIndex_++;
                }
                else
                {
                    int gMIN = UCharacterName.GetGroupMin(gMSB);
                    if (gMIN > limit)
                    {
                        gMIN = limit;
                    }
                    if (m_choice_ == (int)UCharacterNameChoice.ExtendedCharName)
                    {
                        if (!IterateExtended(result, gMIN))
                        {
                            return(false);
                        }
                    }
                    m_current_ = gMIN;
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        // protected methods -------------------------------------------------

        /// <summary>
        /// Read and break up the stream of data passed in as arguments and fills up
        /// UCharacterName. If unsuccessful false will be returned.
        /// </summary>
        ///
        /// <param name="data">instance of datablock</param>
        /// <exception cref="IOException">thrown when there's a data error.</exception>
        protected internal void Read(UCharacterName data)
        {
            // reading index
            m_tokenstringindex_ = m_dataInputStream_.ReadInt();
            m_groupindex_       = m_dataInputStream_.ReadInt();
            m_groupstringindex_ = m_dataInputStream_.ReadInt();
            m_algnamesindex_    = m_dataInputStream_.ReadInt();

            // reading tokens
            int count = m_dataInputStream_.ReadChar();

            char[] token = new char[count];
            for (char i = (char)(0); i < count; i++)
            {
                token[i] = m_dataInputStream_.ReadChar();
            }
            int size = m_groupindex_ - m_tokenstringindex_;

            byte[] tokenstr = new byte[size];
            m_dataInputStream_.ReadFully(tokenstr);
            data.SetToken(token, tokenstr);

            // reading the group information records
            count = m_dataInputStream_.ReadChar();
            data.SetGroupCountSize(count, GROUP_INFO_SIZE_);
            count *= GROUP_INFO_SIZE_;
            char[] group = new char[count];
            for (int i_0 = 0; i_0 < count; i_0++)
            {
                group[i_0] = m_dataInputStream_.ReadChar();
            }

            size = m_algnamesindex_ - m_groupstringindex_;
            byte[] groupstring = new byte[size];
            m_dataInputStream_.ReadFully(groupstring);

            data.SetGroup(group, groupstring);

            count = m_dataInputStream_.ReadInt();
            UCharacterName.AlgorithmName[] alg = new UCharacterName.AlgorithmName[count];

            for (int i_1 = 0; i_1 < count; i_1++)
            {
                UCharacterName.AlgorithmName an = ReadAlg();
                if (an == null)
                {
                    throw new IOException(
                              "unames.icu read error: Algorithmic names creation error");
                }
                alg[i_1] = an;
            }
            data.SetAlgorithm(alg);
        }
Exemplo n.º 5
0
        // protected constructor ---------------------------------------------

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name">Name data.</param>
        /// <param name="choice">Name choice from the class <see cref="UCharacterNameChoice"/>.</param>
        public UCharacterNameEnumerator(UCharacterName name, UCharacterNameChoice choice)
        {
            if (name == null)
            {
                throw new ArgumentException("UCharacterName name argument cannot be null. Missing unames.icu?");
            }
            m_name_ = name;
            // no explicit choice in UChar so no checks on choice
            m_choice_  = (int)choice;
            m_start_   = UChar.MinValue;
            m_limit_   = UChar.MaxValue + 1;
            m_current_ = m_start_;
        }
        // protected constructor ---------------------------------------------

        /// <summary>
        /// Constructor
        /// </summary>
        ///
        /// <param name="name">name data</param>
        /// <param name="choice">name choice from the classcom.ibm.icu.lang.UCharacterNameChoice</param>
        /// @draft 2.1
        protected internal UCharacterNameIterator(UCharacterName name, int choice)
        {
            this.m_groupIndex_     = -1;
            this.m_algorithmIndex_ = -1;
            if (name == null)
            {
                throw new ArgumentException(
                          "UCharacterName name argument cannot be null. Missing unames.icu?");
            }
            m_name_ = name;
            // no explicit choice in UCharacter so no checks on choice
            m_choice_  = choice;
            m_start_   = IBM.ICU.Lang.UCharacter.MIN_VALUE;
            m_limit_   = IBM.ICU.Lang.UCharacter.MAX_VALUE + 1;
            m_current_ = m_start_;
        }
Exemplo n.º 7
0
        // protected methods -------------------------------------------------

        /// <summary>
        /// Read and break up the stream of data passed in as arguments
        /// and fills up <see cref="UCharacterName"/>.
        /// If unsuccessful false will be returned.
        /// </summary>
        /// <param name="data">Instance of datablock.</param>
        /// <exception cref="IOException">Thrown when there's a data error.</exception>
        internal void Read(UCharacterName data)
        {
            // reading index
            m_tokenstringindex_ = m_byteBuffer_.GetInt32();
            m_groupindex_       = m_byteBuffer_.GetInt32();
            m_groupstringindex_ = m_byteBuffer_.GetInt32();
            m_algnamesindex_    = m_byteBuffer_.GetInt32();

            // reading tokens
            int count = m_byteBuffer_.GetChar();

            char[] token = ICUBinary.GetChars(m_byteBuffer_, count, 0);
            int    size  = m_groupindex_ - m_tokenstringindex_;

            byte[] tokenstr = new byte[size];
            m_byteBuffer_.Get(tokenstr);
            data.SetToken(token, tokenstr);

            // reading the group information records
            count = m_byteBuffer_.GetChar();
            data.SetGroupCountSize(count, GROUP_INFO_SIZE_);
            count *= GROUP_INFO_SIZE_;
            char[] group = ICUBinary.GetChars(m_byteBuffer_, count, 0);

            size = m_algnamesindex_ - m_groupstringindex_;
            byte[] groupstring = new byte[size];
            m_byteBuffer_.Get(groupstring);

            data.SetGroup(group, groupstring);

            count = m_byteBuffer_.GetInt32();
            UCharacterName.AlgorithmName[] alg =
                new UCharacterName.AlgorithmName[count];

            for (int i = 0; i < count; i++)
            {
                UCharacterName.AlgorithmName an = ReadAlg();
                if (an == null)
                {
                    throw new IOException("unames.icu read error: Algorithmic names creation error");
                }
                alg[i] = an;
            }
            data.SetAlgorithm(alg);
        }