// Token: 0x060032AE RID: 12974 RVA: 0x000E3E88 File Offset: 0x000E2088
        internal RtfToXamlError AdvanceForUnicode(long nSkip)
        {
            RtfToXamlError rtfToXamlError = RtfToXamlError.None;
            RtfToken       rtfToken       = new RtfToken();

            while (nSkip > 0L && rtfToXamlError == RtfToXamlError.None)
            {
                rtfToXamlError = this.Next(rtfToken, null);
                if (rtfToXamlError != RtfToXamlError.None)
                {
                    break;
                }
                switch (rtfToken.Type)
                {
                default:
                    this.Backup();
                    nSkip = 0L;
                    break;

                case RtfTokenType.TokenText:
                {
                    int rtfIndex = this._rtfIndex;
                    this.Backup();
                    while (nSkip > 0L && this._rtfIndex < rtfIndex)
                    {
                        if (this.CurByte == 92)
                        {
                            this._rtfIndex += 4;
                        }
                        else
                        {
                            this._rtfIndex++;
                        }
                        nSkip -= 1L;
                    }
                    break;
                }

                case RtfTokenType.TokenNewline:
                case RtfTokenType.TokenNullChar:
                    break;

                case RtfTokenType.TokenControl:
                    if (rtfToken.RtfControlWordInfo != null && rtfToken.RtfControlWordInfo.Control == RtfControlWord.Ctrl_BIN)
                    {
                        this.AdvanceForBinary((int)rtfToken.Parameter);
                    }
                    nSkip -= 1L;
                    break;
                }
            }
            return(rtfToXamlError);
        }
Ejemplo n.º 2
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        /// <summary>
        ///
        /// </summary>
        /// <param name="token"></param>
        /// <param name="formatState"></param>
        /// <returns></returns>
        internal RtfToXamlError Next(RtfToken token, FormatState formatState)
        {
            RtfToXamlError rtfToXamlError = RtfToXamlError.None;

            _rtfLastIndex = _rtfIndex;

            token.Empty();

            if (_rtfIndex >= _rtfBytes.Length)
            {
                token.Type = RtfTokenType.TokenEOF;
                return(rtfToXamlError);
            }

            int  rtfStartIndex = _rtfIndex;
            byte tokenChar     = _rtfBytes[_rtfIndex++];

            switch (tokenChar)
            {
            // GroupStart
            case (byte)'{':
                token.Type = RtfTokenType.TokenGroupStart;
                break;

            // GroupEnd
            case (byte)'}':
                token.Type = RtfTokenType.TokenGroupEnd;
                break;

            // Control Word
            case (byte)'\r':
            case (byte)'\n':
                token.Type = RtfTokenType.TokenNewline;
                break;

            case (byte)0:
                token.Type = RtfTokenType.TokenNullChar;
                break;

            case (byte)'\\':
                // Input ends with control sequence
                if (_rtfIndex >= _rtfBytes.Length)
                {
                    token.Type = RtfTokenType.TokenInvalid;
                }
                // Normal control character
                else
                {
                    if (IsControlCharValid(CurByte))
                    {
                        int controlStartIndex = _rtfIndex;

                        // Set _rtfIndex to get actual control
                        SetRtfIndex(token, controlStartIndex);

                        // Also provide actual control text - useful for unknown controls
                        token.Text = CurrentEncoding.GetString(_rtfBytes, controlStartIndex - 1, _rtfIndex - rtfStartIndex);
                    }
                    // Hex character
                    else if (CurByte == (byte)'\'')
                    {
                        _rtfIndex--;
                        return(NextText(token));
                    }
                    // Explicit destination
                    else if (CurByte == '*')
                    {
                        _rtfIndex++;
                        token.Type = RtfTokenType.TokenDestination;
                    }
                    // Quoted control character (be generous) - should be limited to "'-*;\_{|}~"
                    else
                    {
                        token.Type = RtfTokenType.TokenTextSymbol;
                        token.Text = CurrentEncoding.GetString(_rtfBytes, _rtfIndex, 1);

                        _rtfIndex++;
                    }
                }

                break;

            // Text or Picture data
            default:
                _rtfIndex--;

                if (formatState != null && formatState.RtfDestination == RtfDestination.DestPicture)
                {
                    token.Type = RtfTokenType.TokenPictureData;
                    break;
                }
                else
                {
                    return(NextText(token));
                }
            }

            return(rtfToXamlError);
        }
Ejemplo n.º 3
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        /// <summary>
        /// Called to process sequence of text and \'hh encoded bytes.
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        private RtfToXamlError NextText(RtfToken token)
        {
            RtfToXamlError rtfToXamlError = RtfToXamlError.None;

            _rtfLastIndex = _rtfIndex;

            token.Empty();
            token.Type = RtfTokenType.TokenText;

            int  s       = _rtfIndex;
            int  e       = s;
            bool bSawHex = false;

            while (e < _rtfBytes.Length)
            {
                if (IsControl(_rtfBytes[e]))
                {
                    if (_rtfBytes[e] == (byte)'\\' &&
                        e + 3 < _rtfBytes.Length &&
                        _rtfBytes[e + 1] == '\'' &&
                        IsHex(_rtfBytes[e + 2]) &&
                        IsHex(_rtfBytes[e + 3]))
                    {
                        e      += 4;
                        bSawHex = true;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (_rtfBytes[e] == '\r' || _rtfBytes[e] == '\n' || _rtfBytes[e] == 0)
                {
                    break;
                }
                else
                {
                    e++;
                }
            }

            if (s == e)
            {
                token.Type = RtfTokenType.TokenInvalid;
            }
            else
            {
                _rtfIndex = e;

                if (bSawHex)
                {
                    int    i     = 0;
                    int    n     = e - s;
                    byte[] bytes = new byte[n];
                    while (s < e)
                    {
                        if (_rtfBytes[s] == '\\')
                        {
                            bytes[i++] = (byte)((byte)(HexToByte(_rtfBytes[s + 2]) << 4) + HexToByte(_rtfBytes[s + 3]));
                            s         += 4;
                        }
                        else
                        {
                            bytes[i++] = _rtfBytes[s++];
                        }
                    }

                    token.Text = CurrentEncoding.GetString(bytes, 0, i);
                }
                else
                {
                    token.Text = CurrentEncoding.GetString(_rtfBytes, s, e - s);
                }
            }

            return(rtfToXamlError);
        }
Ejemplo n.º 4
0
        internal RtfToXamlError AdvanceForUnicode(long nSkip)
        {
            RtfToXamlError rtfToXamlError = RtfToXamlError.None;

            // Advancing for text is a little tricky
            RtfToken token = new RtfToken();

            while (nSkip > 0 && rtfToXamlError == RtfToXamlError.None)
            {
                rtfToXamlError = Next(token, /*formatState:*/ null);

                if (rtfToXamlError != RtfToXamlError.None)
                {
                    break;
                }

                switch (token.Type)
                {
                default:
                case RtfTokenType.TokenGroupStart:
                case RtfTokenType.TokenGroupEnd:
                case RtfTokenType.TokenInvalid:
                case RtfTokenType.TokenEOF:
                case RtfTokenType.TokenDestination:
                    Backup();
                    nSkip = 0;
                    break;

                case RtfTokenType.TokenControl:
                    if (token.RtfControlWordInfo != null && token.RtfControlWordInfo.Control == RtfControlWord.Ctrl_BIN)
                    {
                        AdvanceForBinary((int)token.Parameter);
                    }
                    nSkip--;
                    break;

                case RtfTokenType.TokenNewline:
                    // Newlines don't count for skipping purposes
                    break;

                case RtfTokenType.TokenNullChar:
                    // Null chars don't count for skipping purposes
                    break;

                case RtfTokenType.TokenText:
                    // We need to skip *bytes*, considering hex-encoded control words as a single byte.
                    // Since Next() returned TokenText, we know that we can safely assume that the next
                    // sequence of bytes is either simple text or hex-encoded bytes.
                    int nEndTextIndex = _rtfIndex;
                    Backup();
                    while (nSkip > 0 && _rtfIndex < nEndTextIndex)
                    {
                        if (CurByte == '\\')
                        {
                            _rtfIndex += 4;
                        }
                        else
                        {
                            _rtfIndex++;
                        }
                        nSkip--;
                    }
                    break;
                }
            }

            return(rtfToXamlError);
        }
        // Token: 0x060032B5 RID: 12981 RVA: 0x000E40E0 File Offset: 0x000E22E0
        private RtfToXamlError NextText(RtfToken token)
        {
            RtfToXamlError result = RtfToXamlError.None;

            this._rtfLastIndex = this._rtfIndex;
            token.Empty();
            token.Type = RtfTokenType.TokenText;
            int  i    = this._rtfIndex;
            int  j    = i;
            bool flag = false;

            while (j < this._rtfBytes.Length)
            {
                if (this.IsControl(this._rtfBytes[j]))
                {
                    if (this._rtfBytes[j] != 92 || j + 3 >= this._rtfBytes.Length || this._rtfBytes[j + 1] != 39 || !this.IsHex(this._rtfBytes[j + 2]) || !this.IsHex(this._rtfBytes[j + 3]))
                    {
                        break;
                    }
                    j   += 4;
                    flag = true;
                }
                else
                {
                    if (this._rtfBytes[j] == 13 || this._rtfBytes[j] == 10 || this._rtfBytes[j] == 0)
                    {
                        break;
                    }
                    j++;
                }
            }
            if (i == j)
            {
                token.Type = RtfTokenType.TokenInvalid;
            }
            else
            {
                this._rtfIndex = j;
                if (flag)
                {
                    int    count = 0;
                    int    num   = j - i;
                    byte[] array = new byte[num];
                    while (i < j)
                    {
                        if (this._rtfBytes[i] == 92)
                        {
                            array[count++] = (byte)(this.HexToByte(this._rtfBytes[i + 2]) << 4) + this.HexToByte(this._rtfBytes[i + 3]);
                            i += 4;
                        }
                        else
                        {
                            array[count++] = this._rtfBytes[i++];
                        }
                    }
                    token.Text = this.CurrentEncoding.GetString(array, 0, count);
                }
                else
                {
                    token.Text = this.CurrentEncoding.GetString(this._rtfBytes, i, j - i);
                }
            }
            return(result);
        }
        // Token: 0x060032AD RID: 12973 RVA: 0x000E3CC8 File Offset: 0x000E1EC8
        internal RtfToXamlError Next(RtfToken token, FormatState formatState)
        {
            RtfToXamlError result = RtfToXamlError.None;

            this._rtfLastIndex = this._rtfIndex;
            token.Empty();
            if (this._rtfIndex >= this._rtfBytes.Length)
            {
                token.Type = RtfTokenType.TokenEOF;
                return(result);
            }
            int rtfIndex = this._rtfIndex;

            byte[] rtfBytes  = this._rtfBytes;
            int    rtfIndex2 = this._rtfIndex;

            this._rtfIndex = rtfIndex2 + 1;
            byte b = rtfBytes[rtfIndex2];

            if (b <= 13)
            {
                if (b == 0)
                {
                    token.Type = RtfTokenType.TokenNullChar;
                    return(result);
                }
                if (b == 10 || b == 13)
                {
                    token.Type = RtfTokenType.TokenNewline;
                    return(result);
                }
            }
            else if (b != 92)
            {
                if (b == 123)
                {
                    token.Type = RtfTokenType.TokenGroupStart;
                    return(result);
                }
                if (b == 125)
                {
                    token.Type = RtfTokenType.TokenGroupEnd;
                    return(result);
                }
            }
            else
            {
                if (this._rtfIndex >= this._rtfBytes.Length)
                {
                    token.Type = RtfTokenType.TokenInvalid;
                    return(result);
                }
                if (this.IsControlCharValid(this.CurByte))
                {
                    int rtfIndex3 = this._rtfIndex;
                    this.SetRtfIndex(token, rtfIndex3);
                    token.Text = this.CurrentEncoding.GetString(this._rtfBytes, rtfIndex3 - 1, this._rtfIndex - rtfIndex);
                    return(result);
                }
                if (this.CurByte == 39)
                {
                    this._rtfIndex--;
                    return(this.NextText(token));
                }
                if (this.CurByte == 42)
                {
                    this._rtfIndex++;
                    token.Type = RtfTokenType.TokenDestination;
                    return(result);
                }
                token.Type = RtfTokenType.TokenTextSymbol;
                token.Text = this.CurrentEncoding.GetString(this._rtfBytes, this._rtfIndex, 1);
                this._rtfIndex++;
                return(result);
            }
            this._rtfIndex--;
            if (formatState == null || formatState.RtfDestination != RtfDestination.DestPicture)
            {
                return(this.NextText(token));
            }
            token.Type = RtfTokenType.TokenPictureData;
            return(result);
        }