<div dir="ltr">On Wed, May 22, 2013 at 11:41 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, May 22, 2013 at 9:20 AM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
  You can tokenize without a lexer, but the line/caret combo might actually be better. Nice work!<br>
<br>
<br>
================<br>
Comment at: lib/Basic/SourceLocation.cpp:70-71<br>
@@ +69,4 @@<br>
<div>+  StringRef Buffer = SM.getBufferData(LocInfo.first);<br>
+  int First = std::max<int>(Buffer.rfind('\n', LocInfo.second) + 1, 0);<br>
+  int Last = std::min<int>(Buffer.find('\n', LocInfo.second), Buffer.size());<br>
+  OS << "|" << Buffer.substr(First, Last - First) << "|\n" << IndentStr<br>
</div>----------------<br>
Not super-happy about relying on the value of StringRef::npos here, but okay.<br></blockquote><div><br></div></div><div>Aren't these min/max calls both redundant? Assuming we're not dealing with buffers longer than 2^31 characters, they're equivalent to:</div>

<div><br></div><div>int First = Buffer.rfind('\n', LocInfo.second) + 1; // because this is never negative</div><div>int Last = Buffer.find('\n', LocInfo.second); // because this is never >= Buffer.size() after conversion to int</div>

<div> <br></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div></div><div>These are both exactly what was wanted, but should be of type size_t (== StringRef::size_type).</div>
</div>
</blockquote></div><br></div><div class="gmail_extra" style>They were left-overs that I didn't actually want to rely on, but forgot to clean up :) I think the latest version is easier to understand, ptal...</div></div>