mirror of https://github.com/CGAL/cgal
Fix null char reading and backslash separated multi lines
This commit is contained in:
parent
451223a2e8
commit
b7ca320000
|
|
@ -25,6 +25,7 @@
|
|||
#include <boost/utility/enable_if.hpp>
|
||||
#include <CGAL/boost/graph/Named_function_parameters.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
|
@ -72,12 +73,30 @@ bool read_OBJ(std::istream& is,
|
|||
bool tex_found(false), norm_found(false);
|
||||
while(getline(is, line))
|
||||
{
|
||||
if(line.empty())
|
||||
continue;
|
||||
// get last non-whitespace, non-null character
|
||||
auto last = std::find_if(line.rbegin(), line.rend(), [](char c) { return c != '\0' && !std::isspace(c); });
|
||||
if(last == line.rend())
|
||||
continue; // line is empty or only whitespace
|
||||
|
||||
// keep reading lines as long as the last non-whitespace, non-null character is a backslash
|
||||
while(last != line.rend() && *last == '\\')
|
||||
{
|
||||
// remove everything from the backslash (included)
|
||||
line = line.substr(0, line.size() - (last - line.rbegin()) - 1);
|
||||
|
||||
std::string next_line;
|
||||
if(!getline(is, next_line))
|
||||
break;
|
||||
|
||||
line += next_line;
|
||||
last = std::find_if(line.rbegin(), line.rend(), [](char c) { return c != '\0' && !std::isspace(c); });
|
||||
}
|
||||
|
||||
CGAL_assertion(!line.empty());
|
||||
|
||||
std::istringstream iss(line);
|
||||
if(!(iss >> s))
|
||||
continue; // can't read anything on the line, whitespace only?
|
||||
continue;
|
||||
|
||||
if(s == "v")
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue