[Bf-blender-cvs] [a662ddd76a1] soc-2020-io-performance: Read multiple lines with \\n line breaks.

Ankit Meel noreply at git.blender.org
Sun Aug 23 21:09:35 CEST 2020


Commit: a662ddd76a1b5143f8b458297ab9a853cc19d644
Author: Ankit Meel
Date:   Mon Aug 24 00:37:41 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBa662ddd76a1b5143f8b458297ab9a853cc19d644

Read multiple lines with \\n line breaks.

===================================================================

M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc

===================================================================

diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 48b4895061c..eac242299c3 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -35,6 +35,24 @@ namespace blender::io::obj {
 
 using std::string;
 
+/**
+ * Store multiple lines separated by an escaped newline character: `\\n`.
+ */
+static void read_next_line(std::ifstream &file, string &r_line)
+{
+  std::string new_line;
+  while (file.good() && r_line.back() == '\\') {
+    new_line.clear();
+    bool ok = static_cast<bool>(std::getline(file, new_line));
+    /* Remove the last backslash character. */
+    r_line.pop_back();
+    r_line.append(new_line);
+    if (!ok || new_line.empty()) {
+      return;
+    }
+  }
+}
+
 /**
  * Split a line string into the first word (key) and the rest of the line.
  * Also remove leading & trailing spaces as well as `\r` carriage return
@@ -275,6 +293,10 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<Geometry>> &r_all_geometr
   string object_group{};
 
   while (std::getline(obj_file_, line)) {
+    /* Keep reading new lines if the last character is `\`. */
+    /* Another way is to make a getline wrapper and use it in the while condition. */
+    read_next_line(obj_file_, line);
+
     StringRef line_key, rest_line;
     split_line_key_rest(line, line_key, rest_line);
     if (line.empty() || rest_line.is_empty()) {



More information about the Bf-blender-cvs mailing list