On Wednesday, September 17, 2014, Diego Novillo <<a href="mailto:dnovillo@google.com">dnovillo@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>In this hunk. I'm not really sure why you needed to change the sign of the loop. Is it because you advanced the line number above?</div><div><br></div><div>@@ -61,9 +72,9 @@ void line_iterator::advance() {</div><div> </div><div>   // Measure the line.</div><div>   size_t Length = 0;</div><div>-  do {</div><div>+  while (Pos[Length] != '\0' && Pos[Length] != '\n') {</div><div>     ++Length;</div><div>-  } while (Pos[Length] != '\0' && Pos[Length] != '\n');</div><div>+  }</div><div> </div><div>   CurrentLine = StringRef(Pos, Length);</div><div> }</div></div></blockquote><div><br></div><div>Since the line can have zero length now, we have to check the condition first. The old way would step over the newline at Pos[0].</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Also, skipping blank lines in your patch seems to have a counter intuitive semantics. If I'm skipping blank lines, it means I don't want to be returned a blank line, but I still expect the line number to be increased. In this patch, that does not seem to happen. In fact, the test here seems wrong:</div></div></blockquote><div></div><div><br></div><div>I think you've misread something here - the line number is increased when we skip blank lines. The behaviour when SkipBlanks is true is unchanged from without this patch.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>-TEST(LineIteratorTest, CommentSkipping) {</div><div>+TEST(LineIteratorTest, CommentAndBlankSkipping) {</div><div>   std::unique_ptr<MemoryBuffer> Buffer(</div><div>       MemoryBuffer::getMemBuffer("line 1\n"</div><div>                                  "line 2\n"</div><div>                                  "# Comment 1\n"</div><div>-                                 "line 4\n"</div><div>+                                 "\n"</div><div>+                                 "line 5\n"</div><div>+                                 "\n"</div><div>                                  "# Comment 2"));</div><div> </div><div>-  line_iterator I = line_iterator(*Buffer, '#'), E;</div><div>+  line_iterator I = line_iterator(*Buffer, true, '#'), E;</div><div> </div><div>   EXPECT_FALSE(I.is_at_eof());</div><div>   EXPECT_NE(E, I);</div><div>@@ -59,14 +61,51 @@ TEST(LineIteratorTest, CommentSkipping) {</div><div>   EXPECT_EQ("line 2", *I);</div><div>   EXPECT_EQ(2, I.line_number());</div><div>   ++I;</div><div>-  EXPECT_EQ("line 4", *I);</div><div>-  EXPECT_EQ(4, I.line_number());</div><div>+  EXPECT_EQ("line 5", *I);</div><div>+  EXPECT_EQ(5, I.line_number());</div><div>+  ++I;</div></div><div><br></div><div>The string "line 5" is really at line 6, so I.line_number() should return 6, not 5.</div></div></blockquote><div><br></div><div>No, the string "Line 5" is really line 5. Note that an extra newline was added to the test, so line 4 is now blank.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>I would also expect the BlankSkipping test to be failing here.</div></div></blockquote><div><br></div><div>Why? </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Diego.</div></div>
</blockquote>