MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / parse

Method parse

external/httplib.h:4790–4925  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4788 bool is_valid() const { return is_valid_; }
4789
4790 bool parse(const char *buf, size_t n, const ContentReceiver &content_callback,
4791 const MultipartContentHeader &header_callback) {
4792
4793 buf_append(buf, n);
4794
4795 while (buf_size() > 0) {
4796 switch (state_) {
4797 case 0: { // Initial boundary
4798 buf_erase(buf_find(dash_boundary_crlf_));
4799 if (dash_boundary_crlf_.size() > buf_size()) { return true; }
4800 if (!buf_start_with(dash_boundary_crlf_)) { return false; }
4801 buf_erase(dash_boundary_crlf_.size());
4802 state_ = 1;
4803 break;
4804 }
4805 case 1: { // New entry
4806 clear_file_info();
4807 state_ = 2;
4808 break;
4809 }
4810 case 2: { // Headers
4811 auto pos = buf_find(crlf_);
4812 if (pos > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }
4813 while (pos < buf_size()) {
4814 // Empty line
4815 if (pos == 0) {
4816 if (!header_callback(file_)) {
4817 is_valid_ = false;
4818 return false;
4819 }
4820 buf_erase(crlf_.size());
4821 state_ = 3;
4822 break;
4823 }
4824
4825 const auto header = buf_head(pos);
4826
4827 if (!parse_header(header.data(), header.data() + header.size(),
4828 [&](const std::string &, const std::string &) {})) {
4829 is_valid_ = false;
4830 return false;
4831 }
4832
4833 static const std::string header_content_type = "Content-Type:";
4834
4835 if (start_with_case_ignore(header, header_content_type)) {
4836 file_.content_type =
4837 trim_copy(header.substr(header_content_type.size()));
4838 } else {
4839 static const std::regex re_content_disposition(
4840 R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~",
4841 std::regex_constants::icase);
4842
4843 std::smatch m;
4844 if (std::regex_match(header, m, re_content_disposition)) {
4845 Params params;
4846 parse_disposition_params(m[1], params);
4847

Callers 1

read_content_coreMethod · 0.45

Calls 8

parse_headerFunction · 0.85
trim_copyFunction · 0.85
parse_disposition_paramsFunction · 0.85
decode_urlFunction · 0.85
dataMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected