Esempio n. 1
0
        //===============================================================
        // Constructor uses given ICharInputStream
        //

        internal void BasicInitialization()
        {
            LineNo            = 1;
            _inProcessingTag  = 0;
            _inSavedCharacter = -1;
            _inIndex          = 0;
            _inSize           = 0;
            _inNestedSize     = 0;
            _inNestedIndex    = 0;
            _inTokenSource    = TokenSource.Other;
            _maker            = SharedStatics.GetSharedStringMaker();
        }
Esempio n. 2
0
        public string GetString(ref int position, bool bCreate)
        {
            int  stringEnd;
            bool bFoundEnd = false;

            for (stringEnd = position; stringEnd < m_data.Length - 1; stringEnd += 2)
            {
                if (m_data[stringEnd] == 0 && m_data[stringEnd + 1] == 0)
                {
                    bFoundEnd = true;
                    break;
                }
            }

            Contract.Assert(bFoundEnd, "Malformed string in parse data");
            var m = SharedStatics.GetSharedStringMaker();

            try
            {
                if (bCreate)
                {
                    m._outStringBuilder = null;
                    m._outIndex         = 0;

                    for (int i = position; i < stringEnd; i += 2)
                    {
                        char c = (char)(m_data[i] << 8 | m_data[i + 1]);

                        // add character  to the string
                        if (m._outIndex < StringMaker.outMaxSize)
                        {
                            // easy case
                            m._outChars[m._outIndex++] = c;
                        }
                        else
                        {
                            if (m._outStringBuilder == null)
                            {
                                // OK, first check if we have to init the StringBuilder
                                m._outStringBuilder = new StringBuilder();
                            }

                            // OK, copy from _outChars to _outStringBuilder
                            m._outStringBuilder.Append(m._outChars, 0, StringMaker.outMaxSize);

                            // reset _outChars pointer
                            m._outChars[0] = c;
                            m._outIndex    = 1;
                        }
                    }
                }

                position = stringEnd + 2;

                if (bCreate)
                {
                    return(m.MakeString());
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                SharedStatics.ReleaseSharedStringMaker(ref m);
            }
        }