Skip to content

Commit

Permalink
identify crlf change delimeter and skip extra character
Browse files Browse the repository at this point in the history
  • Loading branch information
ladotonia committed Oct 10, 2015
1 parent 4b1af99 commit a0a6d23
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions io/src/ply/ply_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ bool pcl::io::ply::ply_parser::parse (const std::string& filename)
format_type format = pcl::io::ply::unknown;
std::vector< boost::shared_ptr<element> > elements;

char line_delim = '\n';
int char_ignore_count = 0;

// magic
char magic[4];
istream.read (magic, 4);
if (magic[3] == '\r') // Check if CR/LF

// Check if CR/LF, setup delim and char skip
if (magic[3] == '\r'){
istream.ignore (1);
line_delim = '\r';
char_ignore_count = 1;
}

++line_number_;
if (!istream)
{
Expand All @@ -79,8 +88,9 @@ bool pcl::io::ply::ply_parser::parse (const std::string& filename)
if (magic_callback_)
magic_callback_ ();

while (std::getline (istream, line))
while (std::getline (istream, line, line_delim))
{
istream.ignore(char_ignore_count);
++line_number_;
std::istringstream stringstream (line);
stringstream.unsetf (std::ios_base::skipws);
Expand Down Expand Up @@ -522,12 +532,13 @@ bool pcl::io::ply::ply_parser::parse (const std::string& filename)
{
if (element.begin_element_callback)
element.begin_element_callback ();
if (!std::getline (istream, line))
if (!std::getline (istream, line, line_delim))
{
if (error_callback_)
error_callback_ (line_number_, "parse error");
return false;
}
istream.ignore(char_ignore_count);
++line_number_;
std::istringstream stringstream (line);
stringstream.unsetf (std::ios_base::skipws);
Expand Down

0 comments on commit a0a6d23

Please sign in to comment.