コード例 #1
0
ファイル: FIWriter.cs プロジェクト: mamift/LiquidFastInfoset
        /// <summary>
        /// Writes the given text encoded using the specified Restricted Alphabet Encoding.
        /// </summary>
        /// <param name="text">Text to write.</param>
        /// <param name="alphabetTableIndex">Index of restricted alphabet</param>
        /// <exception cref="ArgumentException">A Restricted Alphabet cannot be found for the specified index.</exception>
        /// <exception cref="InvalidOperationException">The <see cref="WriteState"/> is invalid for this operation.</exception>
        /// <exception cref="IndexOutOfRangeException">Index must be between 1 and 256</exception>
        public void WriteRestrictedAlphabetString(string text, int alphabetTableIndex)
        {
            try
            {
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                if (alphabetTableIndex < FIConsts.ENCODING_TABLE_MIN || alphabetTableIndex > FIConsts.ENCODING_TABLE_MAX)
                {
                    throw new IndexOutOfRangeException("alphabetTableIndex");
                }

                ValidateState(FIItemType.Content);

                FIRestrictedAlphabet alphabet = _internalWriter.Vocabulary.RestrictedAlphabet(alphabetTableIndex);

                if (alphabet == null)
                {
                    throw new ArgumentException("Index out of range.");
                }

                _internalWriter.WriteEncodedData(alphabet, text);

                UpdateState(FIItemType.Content);
            }
            catch (Exception ex)
            {
                _state = FIState.Error;
                throw ex;
            }
        }
コード例 #2
0
        internal FIRestrictedAlphabet Alphabet(int fiTableIndex)
        {
            FIRestrictedAlphabet alphabet = null;

            if (fiTableIndex > 0)
            {
                if (fiTableIndex < EXTENDED_RESTRICTED_ALPHABET_START)
                {
                    if (fiTableIndex <= BUILT_IN_RESTRICTED_ALPHABET_COUNT)
                    {
                        // index - 1 to move from FI table index to list index
                        alphabet = _restrictedAlphabets[fiTableIndex - 1];
                    }
                }
                else if (fiTableIndex < EXTENDED_RESTRICTED_ALPHABET_MAX)
                {
                    // to move from FI table index to list index
                    int realIndex = fiTableIndex - (EXTENDED_RESTRICTED_ALPHABET_START - BUILT_IN_RESTRICTED_ALPHABET_COUNT);
                    if (realIndex < _restrictedAlphabets.Length)
                    {
                        alphabet = _restrictedAlphabets[realIndex];
                    }
                }
            }

            return(alphabet);
        }
コード例 #3
0
        internal FIRestrictedAlphabetManager()
        {
            // initialize array
            _restrictedAlphabets   = new FIRestrictedAlphabet[GROW_ARRAY_SIZE];
            _restrictedAlphabetTop = 0;

            // Add built in restricted alphabets
            FIRestrictedAlphabet alphabet = new FIRestrictedAlphabet(RESTRICTED_ALPHABET_VALUES_NUMERIC);

            alphabet.TableIndex = RESTRICTED_ALPHABET_NUMERIC;
            _restrictedAlphabets[_restrictedAlphabetTop] = alphabet;

            alphabet            = new FIRestrictedAlphabet(RESTRICTED_ALPHABET_VALUES_DATE_TIME);
            alphabet.TableIndex = RESTRICTED_ALPHABET_DATE_TIME;
            _restrictedAlphabets[++_restrictedAlphabetTop] = alphabet;
        }
コード例 #4
0
        internal int Add(FIRestrictedAlphabet alphabet)
        {
            // set table index
            alphabet.TableIndex = _restrictedAlphabets.Length + (EXTENDED_RESTRICTED_ALPHABET_START - BUILT_IN_RESTRICTED_ALPHABET_COUNT);

            if (_restrictedAlphabetTop == (_restrictedAlphabets.Length - 1))
            {
                // grow array
                FIRestrictedAlphabet[] destinationArray = new FIRestrictedAlphabet[_restrictedAlphabets.Length + GROW_ARRAY_SIZE];
                if (_restrictedAlphabetTop > 0)
                {
                    Array.Copy(_restrictedAlphabets, destinationArray, (int)(_restrictedAlphabetTop + 1));
                }

                _restrictedAlphabets = destinationArray;
            }

            // add new restricted alphabet
            _restrictedAlphabetTop++;
            _restrictedAlphabets[_restrictedAlphabetTop] = alphabet;

            return(alphabet.TableIndex);
        }