From a0a6d230bea325eff2c6c5007d1e401cb1b4f84f Mon Sep 17 00:00:00 2001 From: Lado Tonia Date: Sat, 10 Oct 2015 11:07:17 -0400 Subject: [PATCH] identify crlf change delimeter and skip extra character --- io/src/ply/ply_parser.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/io/src/ply/ply_parser.cpp b/io/src/ply/ply_parser.cpp index 41b5305ebda..617696e496a 100644 --- a/io/src/ply/ply_parser.cpp +++ b/io/src/ply/ply_parser.cpp @@ -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 > 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) { @@ -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); @@ -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);