当前位置: 首页>>代码示例>>C#>>正文


C# StringReader.ReadSpecifiedLength方法代码示例

本文整理汇总了C#中StringReader.ReadSpecifiedLength方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.ReadSpecifiedLength方法的具体用法?C# StringReader.ReadSpecifiedLength怎么用?C# StringReader.ReadSpecifiedLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringReader的用法示例。


在下文中一共展示了StringReader.ReadSpecifiedLength方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseParameters

        /// <summary>
        /// Parses parameters from specified reader. Reader position must be where parameters begin.
        /// </summary>
        /// <param name="reader">Reader from where to read parameters.</param>
        /// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
        protected void ParseParameters(StringReader reader)
        {
            // Remove all old parameters.
            m_pParameters.Clear();

            // Parse parameters
            while(reader.Available > 0){
                reader.ReadToFirstChar();

                // We have parameter
                if(reader.SourceString.StartsWith(";")){
                    reader.ReadSpecifiedLength(1);
                    string paramString = reader.QuotedReadToDelimiter(new char[]{';',','},false);
                    if(paramString != ""){
                        string[] name_value = paramString.Split(new char[]{'='},2);
                        if(name_value.Length == 2){
                           this.Parameters.Add(name_value[0],TextUtils.UnQuoteString(name_value[1]));
                        }
                        else{
                            this.Parameters.Add(name_value[0],null);
                        }
                    }
                }
                // Next value
                else if(reader.SourceString.StartsWith(",")){
                    break;
                }
                // Unknown data
                else{
                    throw new SIP_ParseException("Unexpected value '" + reader.SourceString + "' !");
                }
            }
        }
开发者ID:dioptre,项目名称:nkd,代码行数:38,代码来源:SIP_t_ValueWithParams.cs

示例2: Parse

        /// <summary>
        /// Parses PERMANENTFLAGS optional response from string.
        /// </summary>
        /// <param name="r">PERMANENTFLAGS optional response reader.</param>
        /// <returns>Returns PERMANENTFLAGS optional response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
        public new static IMAP_t_orc_PermanentFlags Parse(StringReader r)
        {
            if(r == null){
                throw new ArgumentNullException("r");
            }

            if(!r.StartsWith("[PERMANENTFLAGS",false)){
                throw new ArgumentException("Invalid PERMANENTFLAGS response value.","r");
            }

            // Read [
            r.ReadSpecifiedLength(1);
            // Read PERMANENTFLAGS
            r.ReadWord();
            r.ReadToFirstChar();
            string[] flags = r.ReadParenthesized().Split(' ');
            // Read ]
            r.ReadSpecifiedLength(1);

            return new IMAP_t_orc_PermanentFlags(flags);
        }
开发者ID:DJGosnell,项目名称:LumiSoft.Net,代码行数:27,代码来源:IMAP_t_orc_PermanentFlags.cs

示例3: ReadAddresses

        /// <summary>
        /// Reads parenthesized list of addresses.
        /// </summary>
        /// <param name="r">String reader.</param>
        /// <returns>Returns read addresses.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
        private static Mail_t_Address[] ReadAddresses(StringReader r)
        {
            if(r == null){
                throw new ArgumentNullException("r");
            }

            /* RFC 3501 7.4.2.
                An address structure is a parenthesized list that describes an
                electronic mail address.  The fields of an address structure
                are in the following order: personal name, [SMTP]
                at-domain-list (source route), mailbox name, and host name.

                [RFC-2822] group syntax is indicated by a special form of
                address structure in which the host name field is NIL.  If the
                mailbox name field is also NIL, this is an end of group marker
                (semi-colon in RFC 822 syntax).  If the mailbox name field is
                non-NIL, this is a start of group marker, and the mailbox name
                field holds the group name phrase.
            */

            r.ReadToFirstChar();
            if(r.StartsWith("NIL",false)){
                r.ReadWord();

                return null;
            }
            else{
                List<Mail_t_Address> retVal = new List<Mail_t_Address>();
                // Eat addresses starting "(".
                r.ReadSpecifiedLength(1);

                while(r.Available > 0){
                    // We have addresses ending ")".
                    if(r.StartsWith(")")){
                        r.ReadSpecifiedLength(1);
                        break;
                    }

                    // Eat address starting "(".
                    r.ReadSpecifiedLength(1);

                    string personalName = ReadAndDecodeWord(r.ReadWord());
                    string atDomainList = r.ReadWord();
                    string mailboxName  = r.ReadWord();
                    string hostName     = r.ReadWord();

                    retVal.Add(new Mail_t_Mailbox(personalName,mailboxName + "@" + hostName));

                    // Eat address ending ")".
                    r.ReadSpecifiedLength(1);
                }

                return retVal.ToArray();
            }
        }
开发者ID:nbhopson,项目名称:QMail,代码行数:61,代码来源:IMAP_Envelope.cs

示例4: Parse

        /// <summary>
        /// Parses IMAP ENVELOPE from string.
        /// </summary>
        /// <param name="r">String reader.</param>
        /// <returns>Returns parsed IMAP ENVELOPE string.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
        public static IMAP_Envelope Parse(StringReader r)
        {
            if(r == null){
                throw new ArgumentNullException("r");
            }

            /* RFC 3501 7.4.2 ENVELOPE.
                A parenthesized list that describes the envelope structure of a
                message.  This is computed by the server by parsing the
                [RFC-2822] header into the component parts, defaulting various
                fields as necessary.

                The fields of the envelope structure are in the following
                order: date, subject, from, sender, reply-to, to, cc, bcc,
                in-reply-to, and message-id.  The date, subject, in-reply-to,
                and message-id fields are strings.  The from, sender, reply-to,
                to, cc, and bcc fields are parenthesized lists of address
                structures.

                An address structure is a parenthesized list that describes an
                electronic mail address.  The fields of an address structure
                are in the following order: personal name, [SMTP]
                at-domain-list (source route), mailbox name, and host name.

                [RFC-2822] group syntax is indicated by a special form of
                address structure in which the host name field is NIL.  If the
                mailbox name field is also NIL, this is an end of group marker
                (semi-colon in RFC 822 syntax).  If the mailbox name field is
                non-NIL, this is a start of group marker, and the mailbox name
                field holds the group name phrase.

                If the Date, Subject, In-Reply-To, and Message-ID header lines
                are absent in the [RFC-2822] header, the corresponding member
                of the envelope is NIL; if these header lines are present but
                empty the corresponding member of the envelope is the empty
                string.

                    Note: some servers may return a NIL envelope member in the
                    "present but empty" case.  Clients SHOULD treat NIL and
                    empty string as identical.

                    Note: [RFC-2822] requires that all messages have a valid
                    Date header.  Therefore, the date member in the envelope can
                    not be NIL or the empty string.

                    Note: [RFC-2822] requires that the In-Reply-To and
                    Message-ID headers, if present, have non-empty content.
                    Therefore, the in-reply-to and message-id members in the
                    envelope can not be the empty string.

                If the From, To, cc, and bcc header lines are absent in the
                [RFC-2822] header, or are present but empty, the corresponding
                member of the envelope is NIL.

                If the Sender or Reply-To lines are absent in the [RFC-2822]
                header, or are present but empty, the server sets the
                corresponding member of the envelope to be the same value as
                the from member (the client is not expected to know to do
                this).

                    Note: [RFC-2822] requires that all messages have a valid
                    From header.  Therefore, the from, sender, and reply-to
                    members in the envelope can not be NIL.
            */

            // Eat "ENVELOPE".
            r.ReadWord();
            r.ReadToFirstChar();
            // Eat starting "(".
            r.ReadSpecifiedLength(1);

            // Read "date".
            DateTime date = DateTime.MinValue;
            string dateS = r.ReadWord();
            if(dateS != null){
                date = MIME_Utils.ParseRfc2822DateTime(dateS);
            }

            // Read "subject".
            string subject = ReadAndDecodeWord(r.ReadWord());

            // Read "from"
            Mail_t_Address[] from = ReadAddresses(r);

            //Read "sender"
            Mail_t_Address[] sender = ReadAddresses(r);

            // Read "reply-to"
            Mail_t_Address[] replyTo = ReadAddresses(r);

            // Read "to"
            Mail_t_Address[] to = ReadAddresses(r);

            // Read "cc"
//.........这里部分代码省略.........
开发者ID:nbhopson,项目名称:QMail,代码行数:101,代码来源:IMAP_Envelope.cs

示例5: ReadAndDecodeWord

        /// <summary>
        /// Reads and decodes word from reader.
        /// </summary>
        /// <param name="r">String reader.</param>
        /// <returns>Returns decoded word.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
        private static string ReadAndDecodeWord(StringReader r)
        {
            if(r == null){
                throw new ArgumentNullException("r");
            }

            r.ReadToFirstChar();

            // We have string-literal.
            if(r.SourceString.StartsWith("{")){
                int literalSize = Convert.ToInt32(r.ReadParenthesized());
                // Literal has CRLF ending, skip it.
                r.ReadSpecifiedLength(2);

                return MIME_Encoding_EncodedWord.DecodeTextS(r.ReadSpecifiedLength(literalSize));
            }
            else{
                string word = r.ReadWord();
                if(word == null){
                    throw new ParseException("Excpetcted quoted-string or string-literal, but non available.");
                }
                else if(string.Equals(word,"NIL",StringComparison.InvariantCultureIgnoreCase)){
                    return "";
                }
                else{
                    return MIME_Encoding_EncodedWord.DecodeTextS(word);
                }
            }
        }
开发者ID:nbhopson,项目名称:QMail,代码行数:35,代码来源:IMAP_t_Fetch_r_i_Envelope.cs

示例6: ReadString

        /// <summary>
        /// Reads search-key &lt;string&gt; value.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static string ReadString(StringReader reader)
        {
            //Remove spaces from string start
            reader.ReadToFirstChar();

            // We must support:
            //	word
            //  "text"
            //	{string_length}data(string_length)

            // {string_length}data(string_length)
            if (reader.StartsWith("{"))
            {
                // Remove {
                reader.ReadSpecifiedLength("{".Length);

                int dataLength = Convert.ToInt32(reader.QuotedReadToDelimiter('}'));
                return reader.ReadSpecifiedLength(dataLength);
            }

            return TextUtils.UnQuoteString(reader.QuotedReadToDelimiter(' '));
        }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:27,代码来源:IMAP_SearchKey.cs

示例7: Start

            /// <summary>
            /// Starts reading FETCH response.
            /// </summary>
            public void Start()
            {
                // * seqNo FETCH 1data-item/(1*data-item)

                int seqNo = Convert.ToInt32(m_FetchLine.Split(' ')[1]);

                // Notify that current message has changed.
                m_pHandler.SetCurrentSeqNo(seqNo);
                m_pHandler.OnNextMessage();

                m_pFetchReader = new StringReader(m_FetchLine.Split(new char[]{' '},4)[3]);
                if(m_pFetchReader.StartsWith("(")){
                    m_pFetchReader.ReadSpecifiedLength(1);
                }

                // Read data-items.
                while(m_pFetchReader.Available > 0){
                    m_pFetchReader.ReadToFirstChar();
                //*
                    #region BODY

                    if(m_pFetchReader.StartsWith("BODY ",false)){
                    }

                    #endregion

                    #region BODY[<section>]<<origin octet>>

                    else if(m_pFetchReader.StartsWith("BODY[",false)){
                        // Eat BODY word.
                        m_pFetchReader.ReadWord();

                        // Read body-section.
                        string section = m_pFetchReader.ReadParenthesized();

                        // Read origin if any.
                        int offset = -1;
                        if(m_pFetchReader.StartsWith("<")){
                            offset = Convert.ToInt32(m_pFetchReader.ReadParenthesized().Split(' ')[0]);
                        }

                        // Get Message store stream.
                        IMAP_Client_Fetch_Body_EArgs eArgs = new IMAP_Client_Fetch_Body_EArgs(section,offset);
                        m_pHandler.OnBody(eArgs);

                        // We don't have BODY[].
                        m_pFetchReader.ReadToFirstChar();
                        if(m_pFetchReader.StartsWith("NIL",false)){
                            // Eat NIL.
                            m_pFetchReader.ReadWord();
                        }
                        // BODY[] value is returned as string-literal.
                        else if(m_pFetchReader.StartsWith("{",false)){
                            if(eArgs.Stream == null){
                                m_pImap.ReadStringLiteral(Convert.ToInt32(m_pFetchReader.ReadParenthesized()),new JunkingStream());
                            }
                            else{
                                m_pImap.ReadStringLiteral(Convert.ToInt32(m_pFetchReader.ReadParenthesized()),eArgs.Stream);
                            }

                            // Read continuing FETCH line.
                            m_pFetchReader = new StringReader(m_pImap.ReadLine());
                        }
                        // BODY[] is quoted-string.
                        else{
                            m_pFetchReader.ReadWord();
                        }

                        // Notify that message storing has completed.
                        eArgs.OnStoringCompleted();
                    }

                    #endregion
                //*
                    #region BODYSTRUCTURE

                    else if(m_pFetchReader.StartsWith("BODYSTRUCTURE ",false)){
                    }

                    #endregion

                    #region ENVELOPE

                    else if(m_pFetchReader.StartsWith("ENVELOPE ",false)){
                        m_pHandler.OnEnvelope(IMAP_Envelope.Parse(this));
                    }

                    #endregion

                    #region  FLAGS

                    else if(m_pFetchReader.StartsWith("FLAGS ",false)){
                        // Eat FLAGS word.
                        m_pFetchReader.ReadWord();

                        string   flagsList = m_pFetchReader.ReadParenthesized();
                        string[] flags     = new string[0];
//.........这里部分代码省略.........
开发者ID:andreikalatsei,项目名称:milskype,代码行数:101,代码来源:IMAP_Client.cs

示例8: ParseAddresses

        /// <summary>
        /// Parses addresses from IMAP ENVELOPE addresses structure.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private MailboxAddress[] ParseAddresses(StringReader r)
        {
            r.ReadToFirstChar();
            if(r.StartsWith("NIL",false)){
                // Remove NIL
                r.ReadSpecifiedLength("NIL".Length);

                return null;
            }
            else{
                r.ReadToFirstChar();

                // This must be ((address)[*(address)])
                if(!r.StartsWith("(")){
                    throw new Exception("Invalid IMAP ENVELOPE structure !");
                }
                else{
                    // Read addresses
                    string addressesString = r.ReadParenthesized();

                    ArrayList addresses = new ArrayList();
                    StringReader rAddresses = new StringReader(addressesString.Trim());
                    // Now we have (address)[*(address)], read addresses
                    while(rAddresses.StartsWith("(")){
                        addresses.Add(ParseAddress(rAddresses.ReadParenthesized()));

                        rAddresses.ReadToFirstChar();
                    }

                    MailboxAddress[] retVal = new MailboxAddress[addresses.Count];
                    addresses.CopyTo(retVal);

                    return retVal;
                }
            }
        }
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:41,代码来源:IMAP_Envelope.cs

示例9: ParseAddress

        /// <summary>
        /// Parses address from IMAP ENVELOPE address structure.
        /// </summary>
        /// <param name="addressString">Address structure string.</param>
        /// <returns></returns>
        private MailboxAddress ParseAddress(string addressString)
        {
            /* RFC 3501 7.4.2 ENVELOPE
                An address structure is a parenthesized list that describes an
                electronic mail address.  The fields of an address structure
                are in the following order: personal name, [SMTP]
                at-domain-list (source route), mailbox name, and host name.
            */

            StringReader r = new StringReader(addressString.Trim());
            string personalName = "";
            string emailAddress = "";

            // personal name
            if(r.StartsWith("NIL",false)){
                // Remove NIL
                r.ReadSpecifiedLength("NIL".Length);
            }
            else{
                personalName = Core.CanonicalDecode(r.ReadWord());
            }

            // source route, always NIL (not used nowdays)
            r.ReadWord();

            // mailbox name
            if(r.StartsWith("NIL",false)){
                // Remove NIL
                r.ReadSpecifiedLength("NIL".Length);
            }
            else{
                emailAddress = r.ReadWord() + "@";
            }

            // host name
            if(r.StartsWith("NIL",false)){
                // Remove NIL
                r.ReadSpecifiedLength("NIL".Length);
            }
            else{
                emailAddress += r.ReadWord();
            }

            return new MailboxAddress(personalName,emailAddress);
        }
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:50,代码来源:IMAP_Envelope.cs

示例10: Parse

        /// <summary>
        /// Parses "accept-range" from specified reader.
        /// </summary>
        /// <param name="reader">Reader from where to parse.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>reader</b> is null.</exception>
        /// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
        public override void Parse(StringReader reader)
        {
            /*
                accept-range  = media-range [ accept-params ] 
                media-range   = ("*/
            /*" / (m-type SLASH "*") / (m-type SLASH m-subtype)) *(SEMI m-parameter)
                accept-params = SEMI "q" EQUAL qvalue *(SEMI generic-param)
            */

            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            // Parse m-type
            string word = reader.ReadWord();
            if (word == null)
            {
                throw new SIP_ParseException("Invalid 'accept-range' value, m-type is missing !");
            }
            MediaType = word;

            // Parse media and accept parameters !!! thats confusing part, RFC invalid.
            bool media_accept = true;
            while (reader.Available > 0)
            {
                reader.ReadToFirstChar();

                // We have 'next' value, so we are done here.
                if (reader.SourceString.StartsWith(","))
                {
                    break;
                }
                    // We have parameter
                else if (reader.SourceString.StartsWith(";"))
                {
                    reader.ReadSpecifiedLength(1);
                    string paramString = reader.QuotedReadToDelimiter(new[] {';', ','}, false);
                    if (paramString != "")
                    {
                        string[] name_value = paramString.Split(new[] {'='}, 2);
                        string name = name_value[0].Trim();
                        string value = "";
                        if (name_value.Length == 2)
                        {
                            value = name_value[1];
                        }

                        // If q, then accept parameters begin
                        if (name.ToLower() == "q")
                        {
                            media_accept = false;
                        }

                        if (media_accept)
                        {
                            MediaParameters.Add(name, value);
                        }
                        else
                        {
                            Parameters.Add(name, value);
                        }
                    }
                }
                    // Unknown data
                else
                {
                    throw new SIP_ParseException("SIP_t_AcceptRange unexpected prarameter value !");
                }
            }
        }
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:77,代码来源:SIP_t_AcceptRange.cs


注:本文中的StringReader.ReadSpecifiedLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。