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


C++ parser::parse方法代码示例

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


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

示例1: parse

void parse(istream& in, ostream& out, const parser& p, tree_input_format& input_format, const tree_output_format& output_format, unsigned beam_size) {
  string input, output;
  tree t;

  // Read blocks containing input trees
  while (input_format.read_block(in, input)) {
    // Process all trees in the block
    input_format.set_text(input);
    while (input_format.next_tree(t)) {
      // Parse the tree
      p.parse(t, beam_size);

      // Output the parsed tree
      output_format.write_tree(t, output, &input_format);
      out << output << flush;
    }
    if (!input_format.last_error().empty())
      runtime_failure(input_format.last_error());
  }
}
开发者ID:ufal,项目名称:parsito,代码行数:20,代码来源:run_parsito.cpp

示例2: read

std::size_t message::read(std::istream& in,
                          boost::system::error_code& ec,
                          parser& http_parser)
{
    // make sure that we start out with an empty message & clear error_code
    clear();
    ec.clear();
    
    // parse data from file one byte at a time
    boost::tribool parse_result;
    char c;
    while (in) {
        in.read(&c, 1);
        if ( ! in ) {
            ec = make_error_code(boost::system::errc::io_error);
            break;
        }
        http_parser.set_read_buffer(&c, 1);
        parse_result = http_parser.parse(*this, ec);
        if (! boost::indeterminate(parse_result)) break;
    }

    if (boost::indeterminate(parse_result)) {
        if (http_parser.check_premature_eof(*this)) {
            // premature EOF encountered
            if (! ec)
                ec = make_error_code(boost::system::errc::io_error);
        } else {
            // EOF reached when content length unknown
            // assume it is the correct end of content
            // and everything is OK
            parse_result = true;
            ec.clear();
        }
    }
    
    return (http_parser.get_total_bytes_read());
}
开发者ID:aspectron,项目名称:jsx,代码行数:38,代码来源:http_message.cpp

示例3: receive

std::size_t message::receive(tcp::connection& tcp_conn,
                             boost::system::error_code& ec,
                             parser& http_parser)
{
    std::size_t last_bytes_read = 0;

    // make sure that we start out with an empty message
    clear();

    if (tcp_conn.get_pipelined()) {
        // there are pipelined messages available in the connection's read buffer
        const char *read_ptr;
        const char *read_end_ptr;
        tcp_conn.load_read_pos(read_ptr, read_end_ptr);
        last_bytes_read = (read_end_ptr - read_ptr);
        http_parser.set_read_buffer(read_ptr, last_bytes_read);
    } else {
        // read buffer is empty (not pipelined) -> read some bytes from the connection
        last_bytes_read = tcp_conn.read_some(ec);
        if (ec) return 0;
        BOOST_ASSERT(last_bytes_read > 0);
        http_parser.set_read_buffer(tcp_conn.get_read_buffer().data(), last_bytes_read);
    }

    // incrementally read and parse bytes from the connection
    bool force_connection_closed = false;
    boost::tribool parse_result;
    while (true) {
        // parse bytes available in the read buffer
        parse_result = http_parser.parse(*this, ec);
        if (! boost::indeterminate(parse_result)) break;

        // read more bytes from the connection
        last_bytes_read = tcp_conn.read_some(ec);
        if (ec || last_bytes_read == 0) {
            if (http_parser.check_premature_eof(*this)) {
                // premature EOF encountered
                if (! ec)
                    ec = make_error_code(boost::system::errc::io_error);
                return http_parser.get_total_bytes_read();
            } else {
                // EOF reached when content length unknown
                // assume it is the correct end of content
                // and everything is OK
                force_connection_closed = true;
                parse_result = true;
                ec.clear();
                break;
            }
            break;
        }

        // update the HTTP parser's read buffer
        http_parser.set_read_buffer(tcp_conn.get_read_buffer().data(), last_bytes_read);
    }
    
    if (parse_result == false) {
        // an error occurred while parsing the message headers
        return http_parser.get_total_bytes_read();
    }

    // set the connection's lifecycle type
    if (!force_connection_closed && check_keep_alive()) {
        if ( http_parser.eof() ) {
            // the connection should be kept alive, but does not have pipelined messages
            tcp_conn.set_lifecycle(tcp::connection::LIFECYCLE_KEEPALIVE);
        } else {
            // the connection has pipelined messages
            tcp_conn.set_lifecycle(tcp::connection::LIFECYCLE_PIPELINED);
            
            // save the read position as a bookmark so that it can be retrieved
            // by a new HTTP parser, which will be created after the current
            // message has been handled
            const char *read_ptr;
            const char *read_end_ptr;
            http_parser.load_read_pos(read_ptr, read_end_ptr);
            tcp_conn.save_read_pos(read_ptr, read_end_ptr);
        }
    } else {
        // default to close the connection
        tcp_conn.set_lifecycle(tcp::connection::LIFECYCLE_CLOSE);
        
        // save the read position as a bookmark so that it can be retrieved
        // by a new HTTP parser
        if (http_parser.get_parse_headers_only()) {
            const char *read_ptr;
            const char *read_end_ptr;
            http_parser.load_read_pos(read_ptr, read_end_ptr);
            tcp_conn.save_read_pos(read_ptr, read_end_ptr);
        }
    }

    return (http_parser.get_total_bytes_read());
}
开发者ID:aspectron,项目名称:jsx,代码行数:94,代码来源:http_message.cpp


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