Пример #1
0
    csv_reader_iterator & operator++()
    {
        switch (status) {
            case PENULTIMATE:
                status = END;
                return *this;
            case END:
                throw new std::logic_error("Trying to advance invalid iterator");
            case VALID: ;
        }

        wchar_t buffer[BUFFER_SIZE];
        int buffer_size = -1;
        int i = 0;

        load_saved_buffer(buffer, buffer_size);
        current_line.fields.clear();
        skip_newlines(buffer, buffer_size, i);
        if (i == buffer_size && input_stream_p->eof()) {
            status = END;
            return *this;
        }

        // add a column of the csv line in each iteration
        while (true) {
            field_buffer_p->str(L"");
            read_field(buffer, buffer_size, i);

            if (i == buffer_size && input_stream_p->eof()) {
                break;
            }

            fill_buffer_if_empty(buffer, buffer_size, i);

            // end of csv line, were done :)
            if (L'\n' == buffer[i]) {
                break;
            }
            // another column, just continue the loop
            if (delimiter == buffer[i]) {
                i += 1;
                continue;
            }
            throw std::logic_error("Unexpected character encountered");
        }

        skip_newlines(buffer, buffer_size, i);
        if (input_stream_p->eof() && i == buffer_size) {
            input_stream_p = wistream_pt();
            status = PENULTIMATE;
        }
        save_buffer(buffer, buffer_size, i);

        return *this;
    }
Пример #2
0
 size_t read_sequence(std::istream& is, const size_t read, char* const start, const char stop) {
   size_t nread = read;
   while(is && nread < buf_size_ - 1 && is.peek() != stop) {
     // Skip new lines -> get below does like them
     skip_newlines(is);
     is.get(start + nread, buf_size_ - nread);
     nread += is.gcount();
     skip_newlines(is);
   }
   return nread - read;
 }
Пример #3
0
  // Skip quals header and qual values (read_len) of them.
  void skip_quals(std::istream& is, size_t read_len) {
    ignore_line(is);
    size_t quals = 0;
    while(is.good() && quals < read_len) {
      skip_newlines(is);
      is.ignore(read_len - quals + 1, '\n');
      quals += is.gcount();
      if(is)
        ++read_len;
    }
    skip_newlines(is);
    if(quals == read_len && (is.peek() == '@' || is.peek() == EOF))
      return;

    throw std::runtime_error("Invalid fastq sequence");
  }
Пример #4
0
// Scope
ScopeNode* Parser::parse_scope()
{
	auto node = ast.store.alloc<ScopeNode>();
	node->code = *token_iter;
	std::vector<StatementNode*> statements;

	// Open scope
	if (token_iter->type != LPAREN) {
		// Error
		std::ostringstream msg;
		msg << "Opening scope with wrong character: '" << token_iter->text << "'.";
		parsing_error(*token_iter, msg.str());
	}
	++token_iter;

	// Push this scope
	fn_scope.push_scope();

	while (true) {
		skip_newlines();

		// Close scope?
		if (token_iter->type == RPAREN) {
			++token_iter;
			break;
		}
		// Should be an expression
		else {
			statements.push_back(parse_statement());
		}
	}

	node->statements = ast.store.alloc_from_iters(statements.begin(), statements.end());

	// Pop this scope
	fn_scope.pop_scope();

	node->code.text.set_end((token_iter - 1)->text.end());
	return node;
}