/* #line 133 "./ragel/tsip_parser_header_From.rl" */

        public static TSIP_HeaderFrom Parse(String data)
        {
            int             cs       = 0;
            int             p        = 0;
            int             pe       = data.Length;
            int             eof      = pe;
            TSIP_HeaderFrom hdr_from = new TSIP_HeaderFrom();

            int tag_start = 0;


/* #line 392 "../Headers/TSIP_HeaderFrom.cs" */
            {
                cs = tsip_machine_parser_header_From_start;
            }

/* #line 145 "./ragel/tsip_parser_header_From.rl" */

/* #line 399 "../Headers/TSIP_HeaderFrom.cs" */
            {
                sbyte _klen;
                short _trans;
                sbyte _acts;
                sbyte _nacts;
                short _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_From_key_offsets[cs];
                _trans = (short)_tsip_machine_parser_header_From_index_offsets[cs];

                _klen = _tsip_machine_parser_header_From_single_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_From_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_From_trans_keys[_mid])
                        {
                            _lower = (short)(_mid + 1);
                        }
                        else
                        {
                            _trans += (short)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (short)_klen;
                    _trans += (short)_klen;
                }

                _klen = _tsip_machine_parser_header_From_range_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_From_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_From_trans_keys[_mid + 1])
                        {
                            _lower = (short)(_mid + 2);
                        }
                        else
                        {
                            _trans += (short)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (short)_klen;
                }

_match:
                _trans = (short)_tsip_machine_parser_header_From_indicies[_trans];
                cs     = _tsip_machine_parser_header_From_trans_targs[_trans];

                if (_tsip_machine_parser_header_From_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_From_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_From_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_From_actions[_acts++])
                    {
                    case 0:
/* #line 32 "./ragel/tsip_parser_header_From.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 36 "./ragel/tsip_parser_header_From.rl" */
                    {
                        int len = (int)(p - tag_start);
                        if (hdr_from != null && hdr_from.Uri == null)
                        {
                            if ((hdr_from.Uri = TSIP_ParserUri.Parse(data.Substring(tag_start, len))) != null && !String.IsNullOrEmpty(hdr_from.DisplayName))
                            {
                                hdr_from.Uri.DisplayName = hdr_from.DisplayName;
                            }
                        }
                    }
                    break;

                    case 2:
/* #line 45 "./ragel/tsip_parser_header_From.rl" */
                    {
                        hdr_from.DisplayName = TSK_RagelState.Parser.GetString(data, p, tag_start);
                        hdr_from.DisplayName = TSK_String.UnQuote(hdr_from.DisplayName);
                    }
                    break;

                    case 3:
/* #line 50 "./ragel/tsip_parser_header_From.rl" */
                    {
                        hdr_from.Tag = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 4:
/* #line 54 "./ragel/tsip_parser_header_From.rl" */
                    {
                        hdr_from.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_from.Params);
                    }
                    break;

                    case 5:
/* #line 58 "./ragel/tsip_parser_header_From.rl" */
                    {
                    }
                    break;

/* #line 514 "../Headers/TSIP_HeaderFrom.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 146 "./ragel/tsip_parser_header_From.rl" */

            if (cs <
/* #line 531 "../Headers/TSIP_HeaderFrom.cs" */
                108
/* #line 147 "./ragel/tsip_parser_header_From.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'From' header.");
                hdr_from.Dispose();
                hdr_from = null;
            }

            return(hdr_from);
        }
        /* #line 133 "./ragel/tsip_parser_header_From.rl" */
        public static TSIP_HeaderFrom Parse(String data)
        {
            int cs = 0;
            int p = 0;
            int pe = data.Length;
            int eof = pe;
            TSIP_HeaderFrom hdr_from = new TSIP_HeaderFrom();

            int tag_start = 0;

            /* #line 392 "../Headers/TSIP_HeaderFrom.cs" */
            {
            cs = tsip_machine_parser_header_From_start;
            }

            /* #line 145 "./ragel/tsip_parser_header_From.rl" */

            /* #line 399 "../Headers/TSIP_HeaderFrom.cs" */
            {
            sbyte _klen;
            short _trans;
            sbyte _acts;
            sbyte _nacts;
            short _keys;

            if ( p == pe )
            goto _test_eof;
            if ( cs == 0 )
            goto _out;
            _resume:
            _keys = _tsip_machine_parser_header_From_key_offsets[cs];
            _trans = (short)_tsip_machine_parser_header_From_index_offsets[cs];

            _klen = _tsip_machine_parser_header_From_single_lengths[cs];
            if ( _klen > 0 ) {
            short _lower = _keys;
            short _mid;
            short _upper = (short) (_keys + _klen - 1);
            while (true) {
            if ( _upper < _lower )
                break;

            _mid = (short) (_lower + ((_upper-_lower) >> 1));
            if ( data[p] < _tsip_machine_parser_header_From_trans_keys[_mid] )
                _upper = (short) (_mid - 1);
            else if ( data[p] > _tsip_machine_parser_header_From_trans_keys[_mid] )
                _lower = (short) (_mid + 1);
            else {
                _trans += (short) (_mid - _keys);
                goto _match;
            }
            }
            _keys += (short) _klen;
            _trans += (short) _klen;
            }

            _klen = _tsip_machine_parser_header_From_range_lengths[cs];
            if ( _klen > 0 ) {
            short _lower = _keys;
            short _mid;
            short _upper = (short) (_keys + (_klen<<1) - 2);
            while (true) {
            if ( _upper < _lower )
                break;

            _mid = (short) (_lower + (((_upper-_lower) >> 1) & ~1));
            if ( data[p] < _tsip_machine_parser_header_From_trans_keys[_mid] )
                _upper = (short) (_mid - 2);
            else if ( data[p] > _tsip_machine_parser_header_From_trans_keys[_mid+1] )
                _lower = (short) (_mid + 2);
            else {
                _trans += (short)((_mid - _keys)>>1);
                goto _match;
            }
            }
            _trans += (short) _klen;
            }

            _match:
            _trans = (short)_tsip_machine_parser_header_From_indicies[_trans];
            cs = _tsip_machine_parser_header_From_trans_targs[_trans];

            if ( _tsip_machine_parser_header_From_trans_actions[_trans] == 0 )
            goto _again;

            _acts = _tsip_machine_parser_header_From_trans_actions[_trans];
            _nacts = _tsip_machine_parser_header_From_actions[_acts++];
            while ( _nacts-- > 0 )
            {
            switch ( _tsip_machine_parser_header_From_actions[_acts++] )
            {
            case 0:
            /* #line 32 "./ragel/tsip_parser_header_From.rl" */
            {
            tag_start = p;
            }
            break;
            case 1:
            /* #line 36 "./ragel/tsip_parser_header_From.rl" */
            {
            int len = (int)(p  - tag_start);
            if(hdr_from != null && hdr_from.Uri == null){
            if((hdr_from.Uri = TSIP_ParserUri.Parse(data.Substring(tag_start, len))) != null && !String.IsNullOrEmpty(hdr_from.DisplayName)){
                hdr_from.Uri.DisplayName = hdr_from.DisplayName;
            }
            }
            }
            break;
            case 2:
            /* #line 45 "./ragel/tsip_parser_header_From.rl" */
            {
            hdr_from.DisplayName = TSK_RagelState.Parser.GetString(data, p, tag_start);
            hdr_from.DisplayName = TSK_String.UnQuote(hdr_from.DisplayName);
            }
            break;
            case 3:
            /* #line 50 "./ragel/tsip_parser_header_From.rl" */
            {
            hdr_from.Tag = TSK_RagelState.Parser.GetString(data, p, tag_start);
            }
            break;
            case 4:
            /* #line 54 "./ragel/tsip_parser_header_From.rl" */
            {
            hdr_from.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_from.Params);
            }
            break;
            case 5:
            /* #line 58 "./ragel/tsip_parser_header_From.rl" */
            {
            }
            break;
            /* #line 514 "../Headers/TSIP_HeaderFrom.cs" */
            default: break;
            }
            }

            _again:
            if ( cs == 0 )
            goto _out;
            if ( ++p != pe )
            goto _resume;
            _test_eof: {}
            _out: {}
            }

            /* #line 146 "./ragel/tsip_parser_header_From.rl" */

            if( cs <
            /* #line 531 "../Headers/TSIP_HeaderFrom.cs" */
            108
            /* #line 147 "./ragel/tsip_parser_header_From.rl" */
             ){
                TSK_Debug.Error("Failed to parse SIP 'From' header.");
                hdr_from.Dispose();
                hdr_from = null;
            }

            return hdr_from;
        }