boostorg/spirit — pull request #39 by tomoki (2014-06-14 03:55:18+00:00)
Title: Line pos iterator fix

This pull request fixes following bugs.
- line_pos_iterator's column numbering bug.
- line_pos_iterator's get_current_line bug.

Small sample that causes bug is here.
~~~~~~
#include
#include
#include
#include

int main(){
typedef boost::spirit::line_pos_iterator
pos_iterator_t;
{
std::string test = "abc\ndef";
pos_iterator_t begin(test.begin()),
end(test.end());
// print test for debug.
std::cout << std::string(begin,end) << std::endl;

// !!!!column numbering bug!!!!
// 'd'(2,2) should be 'd'(2,1).
for(pos_iterator_t iter=begin;iter!=end;++iter){
std::cout << "'" << *iter << "'"
<< "(" << get_line(iter) << ":" << get_column(begin,iter) << ")"
<< std::endl;
}

// !!!!get_current_line bug!!!!
// When iter is at 'd','e','f',current_line.length() should be 3.
// and,what get_current_line should return when iter is at '\n'?
for(pos_iterator_t iter = begin; iter != end; ++iter){
auto range = get_current_line(begin,iter,end);
std::string current_line(range.begin(),range.end());
std::cout << current_line << " (len:" << current_line.length() << ")"
<< std::endl;
}
}
return 0;
}

~~~~~~

And,I have a few questions.

- Spirit "must" handle CR,LF,CR+LF,LF+CR completely?
I think,it is very hard mission.I couldn't handle it well.
- Should I add Copyright on line_pos_iterator.hpp?